- May
- 62
- 1
I store backups of critical files in a given directory. Each backup produces a unique subdirectory of that directory.
For a potential restore, I want to find the most recent file with a given name in that directory. It makes sense to use a DO loop on that filename, with the output sorted descending by date, so that I can process the first file found and then quit the loop. However, the list of files found is always in ascending order.
This holds true if I sort instead by name or size or ...
What am I missing here?
Here's some sample code:
For a potential restore, I want to find the most recent file with a given name in that directory. It makes sense to use a DO loop on that filename, with the output sorted descending by date, so that I can process the first file found and then quit the loop. However, the list of files found is always in ascending order.
This holds true if I sort instead by name or size or ...
What am I missing here?
Here's some sample code:
Code:
del d:\tmp\list1.txt d:\tmp\list2.txt >& NUL
:: Find all files named MeConfig.db. Sort the output list ASCENDING by date.
do file in /d"D:\croot.backup" /s /o:d "MeConfig.db"
echo file is %_cwd\%file %@filedate[%file,c] >> d:\tmp\list1.txt
enddo
:: Find all files named MeConfig.db. Sort the output list DESCENDING by date.
do file in /d"D:\croot.backup" /s /o:-d "MeConfig.db"
echo file is %_cwd\%file %@filedate[%file,c] >> d:\tmp\list2.txt
enddo
:: Compare the two lists that were created. (Invoke your favorite compare utility.) They are the same.
diff d:\tmp\list1.txt d:\tmp\list2.txt