I have a couple of apps that regularly write datafiles with a changing filename or extension indicatiing the version, like data21234234.txt or data.23423412
At intervals (greater than the file creation interval) I need to grab the latest version of the file and archive it.
I guess I could grab the directory to a text file and play with that, but I'm hoping someone has a better suggestion.
How to ID latest version of a file with changing name
Moderators: JRL, Dorian (MJT support)
Me_again,
Personally, I've always liked the "dir" to a file idea.
Run>cmd /c dir [drive]:\[path] /o-d /b > [drive]:\[path]\[filename]
will give you a file list with only filenames in the list and the newest file at the top of the list descending to the oldest file at the bottom of the list.
ReadLn>[drive]:\[path]\[filename],1,NewestFile
will set "NewestFile" to the name of the newest file in the directory.
If you want the path added to the listing, just add /s after the /b.
Hope this helps,
Dick
Personally, I've always liked the "dir" to a file idea.
Run>cmd /c dir [drive]:\[path] /o-d /b > [drive]:\[path]\[filename]
will give you a file list with only filenames in the list and the newest file at the top of the list descending to the oldest file at the bottom of the list.
ReadLn>[drive]:\[path]\[filename],1,NewestFile
will set "NewestFile" to the name of the newest file in the directory.
If you want the path added to the listing, just add /s after the /b.
Hope this helps,
Dick