copy - Batch: Checking if a file is locked does not work -
i wrote following batch following steps:
- check if file on server opened user
- make backup of file
- open file
2>nul ( >>test.xlsx (call )) if %errorlevel% == 1 goto end @echo off rem date, make if file name friendly /f "tokens=1-4 delims=/ " %%i in ('date/t') set d=%%j-%%k-%%l@%%i@ rem time, make if file name friendly /f "tokens=1-9 delims=:. " %%i in ('time/t') set t=%%i_%%j_%%k%%l set xlsx=%d%%t%.xlsx ren test.xlsx %xlsx% xcopy *.xlsx j:\test\backup ren %xlsx% test.xlsx call test.xlsx :end
the problem is, line wich tries check if file locked not work on server.
can me find mistake in batch?
if write
2>nul ( >>test.xlsx (call )) if %errorlevel% == 1 goto end
you error. if not expected
. 2 instructions in same line without separation.
if converted
2>nul ( >>test.xlsx (call )) & if %errorlevel% == 1 goto end
then problem delayed expansion. %errorlevel%
variable replaced value when line parsed , @ time, first part of has not been executed, no errorlevel set.
if change
2>nul ( >>test.xlsx (call )) if %errorlevel% == 1 goto end
it work
for more concise construct, can try this
(>>test.xlsx call;) 2>nul || goto end
same function, less code.
Comments
Post a Comment