Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hello All,
I am creating a simple batch file to copy files, log the timestamp and log the copy result. However, I got error when using a program to call this batch file concurrently, it flow an error that "The process cannot access the file because it is being used by another process."
It seems that the ECHO having problem when doing concurrent job. I wondering if there is any command in DOS to do the TRY and CATCH action, or WAIT command to access the file when it is available? THANKS.
MY CODE AS BELOW:
:: BACKUP FILE
@ECHO OFFECHO %timestamp% START BACKUP BATCH >> bat.log
SET timestamp=%date:~4,6%%date:~12,2% %time:~0,8%
:SRCFILE
If not exist %1 goto :SRCNO:BACKUP
copy /y %1 %2
SET msg1= ---Backup File %1 success---
GOTO return%errorlevel%:SRCNO
SET msg1= ---BACKUP FAILURE: Source File %1 not found---
ECHO %timestamp% %msg1% (error) >> bat.log
EXIT:return0
ECHO %timestamp% COPY SUCCESS >> bat.log
GOTO end
:return1
ECHO %timestamp% COPY FAILED >> bat.log
GOTO end:end
ECHO End of batch program

Try-catch? No. The closest you could do is:
:loop1
ECHO %timestamp% START BACKUP BATCH >> bat.log || GOTO loop1

I have just run into the same problem under a little different circumstances. The file I am logging to gets locked for no apparent reason. I will let you know if I find anything out.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |