In a previous post I showed how you can test to see if a file is open in a Powershell script. If you don't have, or don't want, to use Powershell you can use the following in a DOS shell:
FOR /F "delims=" %i IN ('DIR /b "\\some path\*.ext" > do (
(( CALL ) >> "\\some path\%i" ) 2>nul && ( MOVE "\\some path\%i" "\\another path\%i" ) || ( ECHO the file is being created ) )
The for loop is important, even if you are looking for a specific file because the part of the command
( CALL ) >> "\\some path\%i" ) 2>nul
is attempting to write to the file. If the file is present and open by another process, this will fail. If the file is not present, it will be created as an empty file (which is why you want the FOR loop as only files that exist will be worked on). If the file is present, this command exits successful and the shell will then execute the MOVE command (or anything else you put between the "( )"), otherwise the shell will execute the ECHO. If the FOR is looking for *.*, this script will test directories, however they will always fail as you cant write text to a directory so the script will print out the text from the ECHO which does not cause issues.
Note, this command will always exit with error level 0, so if you are using this a scheduler you need to look for errors in the output (in Control-M, that is an ON statement where CODE=*, STATEMENT="*cannot*, etc)