Reputation: 65
I have xcopy batch utility which copies files to network drive.
Is there any way to find if any other user is copying files to the same above location before i start??
The whole idea is to prevent overwriting the files when other users are running the same.
Thanks in Advance
Upvotes: 2
Views: 374
Reputation: 70923
9>"w:\target\file.lock" (
xcopy "r:\source\*" "w:\target"
) && ( del "w:\target\file.lock" )
Use a lock file in your target folder.
What it does is redirect to a file (and lock it) inside the target folder the data sent to the stream 9 (there are 10 streams, 0=stdin
, 1=stdout
, 2=stderr
, 3-9
user defined). Nothing will be written to the stream but the output file will be locked.
As the redirection is wrapping the xcopy
command, the lock on the file is maintained until the command ends.
Upvotes: 2
Reputation: 77846
Not absolutely sure but you can use TASKLIST
dos command like below; which will get you the information whether an XCOPY
exe is running already.
TASKLIST /FO TABLE /NH /FI "USERNAME ne NT AUTHORITY\SYSTEM" /FI "STATUS eq running" /FI "IMAGENAME eq XCOPY.exe"
Upvotes: 0