Reputation: 1444
I am new to the batch file process and I followed this post to create a script that copies my most recent file.
How to code a batch file to copy and rename the most recently dated file?
@echo off
setLocal DisableDelayedExpansion
pushd H:\
setLocal EnableDelayedExpansion
for /f "tokens=* delims= " %%G in ('dir/b/od') do (set newest=%%G)
copy %newest% H:\archive\testFile.txt
POPD
I tested with a small file successfully but when I moved to production I received this error:The system cannot find the file specified.
Is there any limitation on file size with this script? The size difference is 1kb for test and 6.5mb for prod. Apart from internal content of the test file, this is the only difference I can think of.
Upvotes: 0
Views: 135
Reputation: 70923
No, size is not a problem. The file is in the disk and all you are doing is copying it. Maybe there is no space and you can not copy the file, but this is not the case here.
Probably the problem is a space in file name and some missing quotes.
@echo off
setLocal enableextensions disabledelayedexpansion
set "newest="
for /f "delims=" %%G in ('dir /b /a-d /od "H:\"') do set "newest=%%~fG"
if defined newest copy "%newest%" "H:\archive\testFile.txt" /y
Upvotes: 0