File to import is systematically created with date as file name.

  • Thread starter Thread starter Steve in MN
  • Start date Start date
S

Steve in MN

The data file that I will need to import into the program every day is a
systematically created .txt file that will be kept in a folder with all the
rest of the past generated files. What is the best way to get the program to
grab the newest file and automatically import that with out user intervention.

I would assume that i might be able to do a left trim on the file name in
the import string if they had a name on the front side of it...that might
work.

But how would one go about looking for the highest create date on a file in
a root folder.

Ex: C:\General\dailyfile\121608.txt
 
Hi Steve,

The following bit of code will get you pointed in the right direction.
Note that it requires the Microsoft Scripting Runtime reference. Go to Tools
menu in VB Editor and choose References. Note also that this recurses into
subfolders, which you probably do not need.

Public Sub GetFileInformation(ByVal strPath As String)

Dim fl As File
Dim fso As New FileSystemObject
Dim fldr1 As Folder
Dim fldr2 As Folder

MsgBox "Processing " & strPath

Set fldr1 = fso.GetFolder(strPath)
For Each fl In fldr1.Files
MsgBox "Name: " & fl.Name & vbCrLf & _
"DateCreated: " & fl.DateCreated & vbCrLf & _
"DateLastAccessed: " & fl.DateLastAccessed & vbCrLf & _
"DateLastModified: " & fl.DateLastModified & vbCrLf & _
"Drive: " & fl.Drive & vbCrLf & _
"ParentFolder: " & fl.ParentFolder & vbCrLf & _
"Path: " & fl.Path & vbCrLf & _
"Size: " & fl.Size & vbCrLf & _
"Type: " & fl.Type & vbCrLf & _
"Extension: " & fso.GetExtensionName(fl.Name)
Next fl
For Each fldr2 In fldr1.SubFolders
GetFileInformation fldr2.Path
Next fldr2

End Sub

Clifford Bass
 
Thanks for the response Cliff.

I just found out that the file will be residing on a Samba drive. From what
i can tell is that is some sort of server that links unix/linux with a
windows platform.
Will the code you wrote below work with that scenario?

Long story, but i cant test it because i'm not working on their domain and
dont have access to it yet.

Steve
 
Hi Steve,

I could not say for total sure, but I would rather surprised if it did
not. That regardless of whether they are mapping it to a drive letter or
just using the \\server.company.com\share\path type of reference.

Clifford Bass
 
Back
Top