Scheduled BAT - Error during XCOPY if file is in use

159 views Asked by At

I have this script scheduled every hour:

@echo off
set path1="E:\Document\Backup"
set path2="E:\Document\NewDoc"
set path3="C:\ScanDoc"

forfiles -p %path1% -s -m *.pdf /D -30 /C "cmd /c del @path"
xcopy %path2%\*.pdf* %path1% /c
start /d %path3% ScanBatch.exe

Files in "NewDoc" folder are created by manual document scanning (PDF FORMAT), so sometimes documents are in use.

The Scanbatch program read files in "Backup" folder, so if PDF is copied from "NewDoc" to "Backup" while in use, it's result as corrupted and the Scanbatch go in error.

Is there a way to copy files ONLY IF NOT IN USE?

1

There are 1 answers

0
Nifriz On BEST ANSWER

At the end the real problem wasn't xcopy, but "Scanbatch.exe" that crashes if found an opened file. Problem solved changing schedulation time.