Robocopy /mov How can i prohibit the file copy if the file is open?

Hello,
i'am using robocopy with switch /mov for moving PDF files and it works.
If the PDF open, Robocopy copy the file to destination bat can not delete the source file.
How can i prohibit the file copy if the file is open?

I'am using : robocopy.exe C:\temp C:\new /MOV

Do you have any ideas?
Thank you very much,
kind regards
bounty457
LVL 1
bounty457Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
QlemoConnect With a Mentor DeveloperCommented:
I can only recommend to skip using RoboCopy for this purpose (there is no need to use it), and switch to the move command:
move \\server\share\path\*.pdf c:\temp\

Open in new window

This works properly if the file cannot be deleted (because of permission issues, or locked files as in your case). The command does not do anything if the file exists at the target - no issue here - and does not work for subfolders - which should not be an issue here either.
1
 
yo_beeDirector of ITCommented:
That is weird. Robocopy skills locked files. That is what the /r:n /w:n switches are meant for.

From my experience with robocopy you would see an error and a default wait time of 30 seconds before the process tries again. It should not move or copy the file if there is a lock on it.  

What machine are your running robocopy from?
0
 
QlemoDeveloperCommented:
There are different modes to open a file, and depending on the one used by the PDF reader the files might be locked for change, but not reading. So RoboCopy is able to copy the file, but not to delete. If the delete fails, RoboCopy should delete the copy.
There are different releases of RoboCopy, each having some own issues, and using a different version might help if RoboCopy does not delete the copied file. Of course the copy will take place each run for nothing that way ...

Anyway, what's the point? /MOV moves the files, leaving only those being created newly or unable to delete. Next run it will check for the file, and either the file exists on the target as exact copy (if the target folder delete failed or didn't took place because of a bug or e.g. network failure), and nothing is copied but the delete retried; or it does not exist and is copied over again.

And another anyway: Why don't you use the move or rename command, which works much better if staying on the same file system (partition)?
0
Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

 
bounty457Author Commented:
Hello,

i'am using MS Server 2008R2.
0
 
bounty457Author Commented:
Hello Qlemlo,

the strange thing is, that robocopy make a new file with _1 or _2 if the file exist.
What i need is a simple process.
1. Move the file from UNC Path to local.
2. If the Source is open in foxit reader do not copy (actualy the file is creating at a every batch run with extension *_1.pdf, *_2.pdf and so on)
3. If the file is closed make the move on next batch run

Thank you very much,
Kind regards
Bounty
0
 
bounty457Author Commented:
Hello,

correction:
The Extension _1, _2 is not from robocopy. The reason is another process...
Strange is, if i use .txt - open in MS Editor and .tif open in MS Paint the move is possible (the source is delete), for me ok. Only the PDF open in Foxit Reader will not deleted.
Kind Regrads
Bounty
0
 
QlemoDeveloperCommented:
Notepad does not lock the file in any way. It loads the file into memory, then closes all handles. So you can do whatever you want with the file ...

For RoboCopy, it should work if you add /IS. I've just tested with an PDF and Adobe, and the result is that the file exists in both locations, and on next batch run isn't considered anymore because it is already on the target. This might be intentional or a bug; but if you add /IS it will try to move the file again.
0
 
Member_2_7970779Commented:
Hello,

thank you very much for the answers.
I am looking for a process that make not a file copy if the file is open. He should check the file, and if deleting is possible, than make a copy.
In my case the following process delete the file. Next robocopy make a copy again.

Thank you very much,
kind regards
Bounty
0
 
bounty457Author Commented:
Hi Qlemo,

thank you very much. This works fine.

Kind Regards
Bounty
0
 
Seth SimmonsSr. Systems AdministratorCommented:
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I have recommended this question be closed as follows:

Accept: Qlemo (https:#a41746308)

If you feel this question should be closed differently, post an objection and the moderators will review all objections and close it as they feel fit. If no one objects, this question will be closed automatically the way described above.

seth2740
Experts-Exchange Cleanup Volunteer
0
All Courses

From novice to tech pro — start learning today.