I have created a batch script to take a file, copy it to a folder with the date and time as the folder name and then to rename the file also based off the date and time. My issue is that any time before 10 AM, the command fails:
c:\ICVERIFY\ICWin420\DATADIR>md C:\SettlementReports\Settlement_Reports\DATADIR\
06-25-2014_ 709_08.24.txt
A subdirectory or file C:\SettlementReports\Settlement_Reports\DATADIR\06-25-201
4_ already exists.
Error occurred while processing: C:\SettlementReports\Settlement_Reports\DATADIR
\06-25-2014_.
Here is my batch file, I have put a time out right before it errors out.
cd c:\
cd icverify
cd icwin420
cd DATADIR
:: this is Regional settings dependent so tweak this according your current settings
Echo %DATE% %Time%
Set TDate=%date:~10,4%%date:~4,2%%date:~7,2% FOR %%V IN (%1) DO Rename %%V %%V%TDate%
md C:\SettlementReports\Settlement_Reports\DATADIR\%date:~4,2%-%date:~7,2%-%date:~10,4%_%time:~0,2%%time:~3,2%_%time:~6,5%.txt
timeout /T 1
copy ICRPT*.txt C:\SettlementReports\Settlement_Reports\DATADIR\%date:~4,2%-%date:~7,2%-%date:~10,4%_%time:~0,2%%time:~3,2%_%time:~6,5%.txt
cd c:\
cd Settlementreports
cd settlement_reports
cd datadir
cd %date:~4,2%-%date:~7,2%-%date:~10,4%_%time:~0,2%%time:~3,2%_%time:~6,5%.txt
ren ICRPT*.TXT ICRPT_%date:~4,2%-%date:~7,2%-%date:~10,4%_%time:~0,2%%time:~3,2%_%time:~6,5%.txt
Any help is greatly appreciated.
Your
%time%
variable contains a space instead of an initial0
left padding the hours for hours less than10:00
. You can useto replace the space with a
0
, storing the resulting value in a new variable. Then replace the references to%time%
with the new variable%$time%
asOr instead, if the space is not a problem in your file names, quote all the file references to avoid the errors
For any of the two options, do the change in all the commands in your file referencing files/folders
replacing the space with a
0
(see MC ND's answer) is one possibility.But you should get used to put any
<path>\file.ext
into doublequotes.is interpreded as
copy file.txt
tonew
, and there are additional parameterspath\file
,with
andspaces.txt
, which are not expected.This syntax works better:
Here there are only two parameters, each enclosed in doublequotes.