04-21-2009 09:42 AM
Hello, I am looking for a quick method to find the most recently updated file name, OR really just one file name in a network folder. My folder has many files inside, so I would prefer to not use any loops, etc.
My confusion starts here: I can use wildcards for some commands to get file information, such as:
FileExist(Directory & "*.TDM")
FileDateGet(Directory & "*.TDM", "fdModify")
I really just want one file name in the folder so that I can use DataFileHeaderAccess. The most recently updated file would be best, but I'm flexible.
Solved! Go to Solution.
04-22-2009 09:28 AM
Hi Julia,
By any chance is this folder declared as a Search Area? If so, then you could use a programmatic DataFinder query to return the most recently modified data file.
Otherwise I would use the filesystemobject in VBScript. I can't seem to get the Item property of the file collection (fc) to work, but it's easy enough to exit the full loop after the first run through:
Directory = "C:\"
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(Directory)
Set fc = f.Files
FOR Each file In fcMsg = Msg & file.Path & vbCRLF
Exit FORNEXT
MsgBox Msg
Also, it really shouldn't take long for the loop to find you the most recent file, even if you have lots of them in that folder:
Directory = "C:\"
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(Directory)
Set fc = f.Files
FOR Each file In fcModifyDate = file.DateLastModified
IF MostRecentDate < ModifyDate THEN
MostRecentDate = ModifyDate
FilePath = file.Path
END IFNEXT
MsgBox FilePath & vbCRLF & MostRecentDate
Bad Turpin
Product Support Engineer
National Instruments
04-22-2009 09:41 AM