Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8870605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:46:41+00:00 2026-06-14T17:46:41+00:00

I’m writing a script to look in a directory, read the file name and

  • 0

I’m writing a script to look in a directory, read the file name and use a part of the file name to run a SQL query to amend a DB, then copy the files to a new location and delete the original.

Once this is done it sends an email confirmation to a predefined email address.

I have the majority in place but am not able to Poll a Dir and process all files that may be there. Im new to this VB.net stuff and to get the other stuff working iv just named it at the beginning.

Any help would be greatly appreciated.

    Dim fileName As String = "C:\temp\Input\VBTEST1.success"
    Dim pathname As String = "C:\temp\Input\"
    Dim result As String
    Dim sourceDir As String = "C:\temp\Input\"
    Dim processedDir As String = "C:\temp\Input\Processed\"
    Dim fList As String() = Directory.GetFiles(sourceDir, "*.success")
    Dim sqlCommand As SqlCommand

    Public Sub Main()
      result = Path.GetFileName(fileName)

      Console.WriteLine("GetFileName('{0}') returns '{1}'", fileName, result)

      Dim betacell As String = result
      betacell = (result.Remove(7, 8))

      Dim connection As New SqlConnection(My.Settings.connectionString)
      connection.Open()

      Dim updateTransaction As SqlTransaction = connection.BeginTransaction()
      Dim sqlQ As String = "UPDATE " & My.Settings.JobTb & " SET Status = '10'  WHERE  JobNumber ='" & betacell & "'"

      sqlCommand = New SqlCommand(sqlQ, connection, updateTransaction)

      sqlCommand.ExecuteNonQuery()
      updateTransaction.Commit()
      connection.Close()
      SendEmail(My.Settings.emailUsers, "EMAIL TEXT")
      Call MoveFiles()

    End Sub

I’m all chuffed now as iv also managed to make it look for all files with a .success extension. Now it processes all files and not the one named in the code.

Module Module1    
Dim sourceDir As String = My.Settings.watchPath
Dim processedDir As String = My.Settings.processedPath

  Private loggerName As String = "EmailReleases"

Public Sub log(ex As Exception)
Console.WriteLine("Error: " & ex.ToString)
End Sub

Public Sub log(ByVal s As String)
Console.WriteLine(DateTime.Now.ToString & " [" & loggerName & "] " & s)
End Sub


Public Sub Main()    
Dim inputFiles As String() = Directory.GetFiles(sourceDir, "*.success")
log("Starting processing of .success files in '" & sourceDir & "' ... ")
If (inputFiles.Length > 0) Then
  Dim connection As New SqlConnection(My.Settings.connectionString)
  connection.Open()
  For Each fileName As String In inputFiles
    Dim sqlCommand As SqlCommand
    Dim fFile As New FileInfo(fileName)
    log(" Processing  " & fFile.Name)
    Dim betacell As String = fFile.Name.Substring(0, fFile.Name.Length - 8)

    'Update Status on Database with the use of the Betacell
    Dim updateTransaction As SqlTransaction = connection.BeginTransaction()
            Dim sqlQ As String = "UPDATE " & My.Settings.JobTb & " SET Status = '10'  WHERE JobNumber ='" & betacell & "'"
    sqlCommand = New SqlCommand(sqlQ, connection, updateTransaction)
    Dim result = sqlCommand.ExecuteNonQuery()

    'Email COnfirmation
    SendEmail(My.Settings.emailUsers, "EMAIL TEXT")
    If (result > 0) Then
      'Move the file
      fFile.MoveTo(processedDir & fFile.Name)
      updateTransaction.Commit() ' make sure to commit only in case moving the file is OK
    Else
      log("ERROR - Betacell '" & betacell & "' not found in database!")
      updateTransaction.Rollback()
    End If
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T17:46:43+00:00Added an answer on June 14, 2026 at 5:46 pm

    Rather than polling a folder (i.e. checking every n seconds whether it has new files) it’s much more efficient to have the operating system notify you of changes in that folder. You can do this by creating a FileSystemWatcher. There is an example on MSDN.

    However, if you did want to poll a folder, it’s actually nice and easy – just wrap the following code in a Timer. Please note I normally code in C#, so apologies if the syntax is not 100%…

    Imports System.IO
    
    ....
    
    For Each file as String in Directory.GetFiles("C:\SomeFolder")
        DoSomethingWithFile (file)
    Next
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want use html5's new tag to play a wav file (currently only supported
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I have a small JavaScript validation script that validates inputs based on Regex. I
In my XML file chapters tag has more chapter tag.i need to display chapters
I am trying to render a haml file in a javascript response like so:
I would like to run a str_replace or preg_replace which looks for certain words

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.