I need to find the most current file in a directory. File names look like file_201009_20110921_072108.txt where the first string is the year/month the data is for the second string is the date the file was generated and the third is the time the file was generated. My challenge is that we have numerous files, but the time stamps change. I am trying to find the most current file based on these 3 elements and then set this as a variable for another batch process.
I was thinking the batch might look like this::
FOR %%1 IN (f:\shared\file_*_*_*.txt) DO SET CurrentFile=%%1
Will this pull the most recent file if I have numerous files with only a date or time change? example:: file_201009_20110921_072108.txt, file_201009_20110921_142208.txt, file_201009_20110928_180108.txt,, we would need only the file_201009_20110928_180108.txt file to be set to "CurrentFile".
Find most current file in a directory
Moderator: DosItHelp
Re: Find most current file in a directory
Doesn't the date and time in the file name match the modified date of the file attributes?
-
- Posts: 2
- Joined: 25 Sep 2012 14:35
Re: Find most current file in a directory
The date and time (second and third strings) would change, but the first string would be variable by month. Does this help with the potential design?
Re: Find most current file in a directory
Squashman wrote:Doesn't the date and time in the file name match the modified date of the file attributes?
What is the answer to this? Are the file date and time the same as in the filename?
Re: Find most current file in a directory
NoMadBanker wrote:The date and time (second and third strings) would change, but the first string would be variable by month. Does this help with the potential design?
That does not answer my question. I am talking about the Files Attributes. (Modified Date, Created date, Last Accessed date.)
Is the modified date and time of the file the same as the Date and time in the file name?
I would assume it is considering you are changing the date in the file name.