|
Answer» Hello, I'm trying to create a simple BATCH file that CHECKS to see if the file exists and then checks the errorlevel to see if it's open or not before proceeding. When I attempt to use the commands below I get the errorlevel==9009 when the file exists and is open or not and I'm not SURE why.
:loop IF EXIST T:\apps\sales\hostdata\ddmartpbk.dat if %errorlevel%==0 goto :run if %errorlevel%==1 goto :loop
:run Copy T:\apps\sales\hostdata\ddmartpbk.dat D:\ddmartpbk.xxx Del T:\apps\sales\hostdata\ddmartpbk.dat
Thanks for your help...
The line starting IF EXIST is incomplete. You have not written a complete test. The syntax for IF is
IF [test] [command]
There is no [command].
You maybe meant this
:loop IF EXIST T:\apps\sales\hostdata\ddmartpbk.dat goto run goto loop
or this
:loop DIR T:\apps\sales\hostdata\ddmartpbk.dat >nul if %errorlevel%==0 goto run goto loop
or even this
:loop DIR T:\apps\sales\hostdata\ddmartpbk.dat >nul && goto run goto loop
but I am not sure what you mean by "checks the errorlevel to see if it's open". What errorlevel? The errorlevel will be 0 if the file exists, and 1 or more if it does not exist. You will not get an indication if the file is "open" that way.
Thanks for the reply...
Yes my code should have read..
IF EXIST T:\apps\sales\hostdata\ddmartpbk.dat goto run
As you can see I'm not that familar with the dos batch commands and I'm trying to FIGURE out how to make this batch process work so I'm open to any suggestions on how to get this done.
I'm trying to write this batch so when a large file is being written to a network disk from another system and my batch script which is running on another system process's the IF EXIST command from above that it doesn't try to do anything with the file until it's done copying.. So I was trying to figure out an errorlevel if the files open at that time and just put the process into a loop until the file is CLOSED..
I hope the makes sense..
Thanks again for your time..if a file is open you cannot rename it so you could test in a loop until success and then rename it back again
|