Ive looked here Batch file to copy directory if it has a later created date than the target directory
for /f "tokens=*" %%a in ('dir/b /od \\machine\c$\location') do set newest=%%a
xcopy /e /k "%newest%" "\\machine\c$\otherlocation"
popd
pause
doesn't work for me:(explained below and above is the code im using)
Dos shows "xcopy /e /k "file.bat" "location" fie not found - file.bat 0 File(s) copied" thing is this file is not the newest created
I've tried various bits of code which I can not get working.
What Im trying to achieve:
Id like a batch file which will search a directory by creation date pick the latest CREATION date then copy to a different direction e.g. file created at 08:16am will get copied rather than the file created at 08:15am on the day of creation.
It'd be amazing if this batch could search by creation date, file type and a string of text from the file name E.g
Files: (in format of Day/Month/Time)
Test01010815.bat created 01/01 08:15
Test01020817.bat created 01/02 08:17
Test01020818.csv created 01/02 08:18
Test01020819.csv created 01/02 08:19
then copies the CSV as I want CSV only and the bottom file as it was the latest created CSV
In the mean time have tried this:
for /f "delims=" %%i in ('dir /b /a-d /od "\\location\STARTTofFILEname*.*"') do set "LatestModifiedFile=%%~i"
xcopy /F /Y "\\el-1311932\c$\batch\export\exe\%LatestModifiedFile%" "\\el-1311932\c$\batch\exe\test\StockExport.csv"