Solved

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

Posted on 2016-08-05
10
40 Views
Last Modified: 2016-09-10
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
0
Comment
Question by:bounty457
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 23

Expert Comment

by:yo_bee
ID: 41744084
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
 
LVL 70

Expert Comment

by:Qlemo
ID: 41744118
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
 
LVL 1

Author Comment

by:bounty457
ID: 41744141
Hello,

i'am using MS Server 2008R2.
0
Edgartown IT Case Study

Learn about Edgartown's quest to ensure the safety and security of the entire town's employee and citizen data. Read the case study!

 
LVL 1

Author Comment

by:bounty457
ID: 41744150
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
 
LVL 1

Author Comment

by:bounty457
ID: 41744159
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
 
LVL 70

Expert Comment

by:Qlemo
ID: 41744234
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
 

Expert Comment

by:Member_2_7970779
ID: 41746237
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
 
LVL 70

Accepted Solution

by:
Qlemo earned 500 total points
ID: 41746308
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
 
LVL 1

Author Comment

by:bounty457
ID: 41746990
Hi Qlemo,

thank you very much. This works fine.

Kind Regards
Bounty
0
 
LVL 35

Expert Comment

by:Seth Simmons
ID: 41792441
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A procedure for exporting installed hotfix details of remote computers using powershell
I was prompted to write this article after the recent World-Wide Ransomware outbreak. For years now, System Administrators around the world have used the excuse of "Waiting a Bit" before applying Security Patch Updates. This type of reasoning to me …
This tutorial will give a short introduction and overview of Backup Exec 2012 and how to navigate and perform basic functions. Click on the Backup Exec button in the upper left corner. From here, are global settings for the application such as conne…
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question