echo off
rem copying latest file with current date from one folder to another folder
cls
echo Copying files. Please wait...
:: echo Would you like to do a copy?
rem pause
for /f "tokens=1-4 delims=/ " %%i in ("%date%") do (
set dow=%%i
set month=%%j
set day=%%k
set year=%%l
)
:: Pad digits with leading zeros e.g Sample_01-01-21.csv
set yy=%year:~-2%
:: Alternate way - set datestr=%date:~0,2%-%date:~3,2%-%date:~6,2%
set datestr=%day%-%month%-%yy%
:: echo "\\networkdrive\Test\Sample_%datestr%.csv"
rem copy files from src to dest e.g copy <src path> <dest path>
copy "D:\Source\Sample_%datestr%.csv" D:\Destination
echo Completed
rem pause
set origFolderPath=..\Source\Customization.Solution
set distFolderPath=.\PublishCustomization.Solution
FOR /F "tokens=*" %%I IN ('DIR "%origFolderPath%\*.zip" /T:C /B /O:D') DO SET "NewestFile=%%I"
copy %origFolderPath%\%NewestFile% %distFolderPath%
技巧在于,在以前的答案中使用的/A-D 检查修改日期,如果你对从源代码控制系统(如 tfs)抓取的文件运行脚本,那么所有编辑过的文件的修改日期都是一样的,然后就会得到一个错误的答案。/T: C 比较创建日期时间,而这在这种情况下可能是一种解决方案。