Need to create a file list for an uploader

emorris1000

Registered User.
Local time
Yesterday, 21:06
Joined
Feb 22, 2011
Messages
125
I have a database that uses uploaded .txt and .csv files that are generated daily. I have a script that automates the uploading but it is very currently unable to automatically find new files (have to point it to the files to reformat->upload).

I would like to have this fully automated. The first step in my psuedocode is to build a list of the files currently in the folder. I can tell this is an FSO solution, but I can't figure out how to make it work. So, does anyone know how to write a script to populate a table with filenames from a location?
 
Can you provide a few more details about your scenario?

I have a process here at work that is similar to what you describe. What I chose to do is just rename the file (via code) when I'm done with it. So, for example;

SomeFileName.txt

becomes;

SomeFileName-I.txt

to indicate that it's already been imported. This makes finding new files very simple.

However, there may be reasons why this scenario would not work for you.
 
Coded solution might look a little like ...
Code:
Sub ParseFilenamesFromFolderToTable(FromFolder As String)
[COLOR="Green"]'  Controls filename parsing,
'  Checks that 'from folder' exists and if so, calls subroutine[/COLOR]
   Dim fso As New Scripting.FileSystemObject
   If fso.FolderExists(FromFolder) Then GetFilenamesFromFolder fso.GetFolder(FromFolder)
End Sub

Private Sub GetFilenamesFromFolder(fd As Scripting.folder)
[COLOR="Green"]'  Traverses files in the given folder 'fd' and calls subroutine for each file[/COLOR]
   Dim f As Scripting.file
   For Each f In fd.files
      InsertFilenameToTable f
   Next
End Sub

Private Sub InsertFilenameToTable(f As Scripting.file)
[COLOR="Green"]'  Inserts a single file name into a table[/COLOR]
   CurrentDb.Execute _
      "INSERT INTO YourTable " & _
         "( Filespec ) " & _
      "VALUES " & _
         "( '" & f.Name & "' )"
End Sub
Note how a solution can be broken down into very small self-documenting sub-routines that do at most one thing. Three steps, identify source folder, traverse files in said folder, save the name of each file - three sub-routines.
Cheers,
Mark
 

Users who are viewing this thread

Back
Top Bottom