Chris
Chris

Reputation: 441

.bat file autocopy - how to only copy file once?

I want a .bat file that will copy all files and folders from one folder to another folder automatically. For example:

robocopy "c:\source" "D:\target" /e /MON:1 /xc /xn /xo

However I need it so that once a file has been copied, that file will not be copied again, even if the copy has been moved to a different directory. Is there any way to do this? Is it possible for robocopy to create a log and check against that before copying the file?

If robocopy can't do it, what can?

Upvotes: 1

Views: 2202

Answers (2)

Mofi
Mofi

Reputation: 49086

Use additionally the option /M on your robocopy (SS64 article) command line as suggested by Stephan because this option results in copying only files with archive attribute set in source folder tree and removing archive attribute by robocopy after successful copying the file.

%SystemRoot%\System32\robocopy.exe "C:\source" "D:\target" /M /E /MON:1 /XC /XN /XO

The archive attribute is automatically set again on file modification.

You could perhaps also use xcopy (SS64 article):

%SystemRoot%\System32\xcopy.exe "C:\source" "D:\target\" /M /E /C /I /Q /G /H /R /K /Y >nul

Important for your task is again option /M for copying only files with archive attribute set in source folder tree and clearing the archive attribute after copying the file.

Note: /I works without user prompt only with target folder path ending with a backslash.

Run in a command prompt window robocopy /? respectively xcopy /? for details on the other options or read the Microsoft documentations for robocopy and xcopy.

Upvotes: 1

PyDever
PyDever

Reputation: 108

Alright So, the easiest way to do this is to copy each file and folder individually, to said folder. This may not be what you are looking for, but I hope it helps! Sadly there is no way to copy l files folders with a single command.

Upvotes: 0

Related Questions