|
Answer» I am creating a BATCH file which should, among other, copy from a known path the most RECENT folder.
ThanksWelcome to the CH forums.
You have not defined what you mean by "most recent folder." This could mean the most recently created folder or the most recently accessed or the folder which has most recently had files added/amended. However....
Modify the paths to suit your requirements and try this:
CODE: [Select]echo off & setlocal cls
set knownpath=c:\windows\system32\
for /f "delims=" %%a in ('dir /ad /od /b "%knownpath%"') do ( set name=%%a )
md "d:\temp\%name%"
copy "%knownpath%%name% d:\temp\%name%\"
This will not copy sub-folders.
Good luck.Thank you very much it was very helpful. BTW one typo in this line copy "%knownpath%%name% d:\temp\%name%\"
should be
copy "%knownpath%\%name%" "d:\temp\%name%\" I disagree about the typo, %knownpath% is already set to C:\Windows\System32\ - ADDING ANOTHER backslash should not be necessary. However, I should have wrapped the source and destination paths/filenames individually in double quotes.
e.g. copy "%knownpath%%name%" "d:\temp\%name%\"
Thanks for coming back with your comments.
|