1

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?

Nifriz
  • 1,033
  • 1
  • 10
  • 21
  • 2
    Have you considered [Robocopy](https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/robocopy) bundled with Windows since Vista? You can use the /w:1 /r:1 switches to indicate the wait and retry times. – Qwerty Apr 27 '22 at 13:55

1 Answers1

1

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

Nifriz
  • 1,033
  • 1
  • 10
  • 21