Robocopy - Copy Files By Date Instead Of By Filename - robocopy

By default Robocopy copies files in order by their filenames. I want to copy the files by date (or date modified) because they appear by date to the end user. (They have no sort, date is the default and only option.)
I have this:
robocopy "C:\directory" "D:\directory" /MIR /R:5 /W:20 /TEE /NP /LOG:"C:\Log.txt"
It is a simple directory copy. Is there a way within Robocopy to copy files by date (or date modified) instead of by filename?
Thank you.

Related

Robocopy log differentiate copy from update

I had THOUGHT that RoboCopy logs could show the action for individual files, i.e. differentiate between a file copied new because it didn't exist in the destination vs file updated because it does exist but is different. But the last time I worked with RoboCopy was Windows 7, and now in Windows 10 I am not seeing anything that looks like a way to get that information in the logs. Am I misremembering, and that was never an option? Or did that functionality get removed? Or am I just missing the argument to make that happen?
FWIW, this is my argument string at the moment
RoboCopy $sourceFolder $destinationFolder /mir /mt /fft /copy:dat /r:10 /w:5 /log:$mirrorLogPath /njh /ns /nc /np

Robocopy is not working in PowerShell

I am trying to run a robocopy script in PowerShell so I can insert it into my other PowerShell script:
$SERVERPATH = "E:\Cisco Config Backups"
$NETWORKPATH = "\\SERVER\Cisco Config Backups"
robocopy $SERVERPATH $NETWORKPATH /E /XC /XN /XO /R:0 /W:0 /COPY:T /LOG:C:\logs\robocopy_logs\config_copy.log /TEE /NP
However when I run this code I see robocopy working where it gives me the following output:
ROBOCOPY :: Robust File Copy for Windows
Started : Thursday, June 30, 2016 1:52:56 PM
Source : E:\Cisco Config Backups
Dest : \\SERVER\Cisco Config Backups
Files : *.*
Options : *.* /TEE /S /E /DCOPY:D /COPY:T /NP /XO /XN /XC /R:0 /W:0
But nothing gets copied over, I want to use robocopy for the logging and so I can have it skip files that already exist.
Please let me know if I am doing anything wrong.
The /COPY:T criteria is specifying to only copy file timestamps, so it is not copying the actual data of the file. However, since there are no files on the destination to copy the timestamps to, nothing happens.
You need to specify at least /COPY:DT so that the file data will be copied, but you can probably just remove the /COPY switch completely as you likely want the file attributes as well, which will get copied by default along with the file data and timestamps.
From robocopy /?:
/COPY:copyflag[s] :: what to COPY for files (default is /COPY:DAT).
(copyflags : D=Data, A=Attributes, T=Timestamps).
(S=Security=NTFS ACLs, O=Owner info, U=aUditing info)
You also need to review all of the switches you are using as some are conflicting--not sure what robocopy does in those cases. As Matt points out in the comment below, you have /E and /S. Do you want to copy empty subdirectories or not? /E specifies to copy empty directories, but /S specifies to NOT copy empty directories.

Insert current date in to destination folder structure

Is it possible to insert todays date in Scandinavian format (yyyymmdd) in to the destination folder when using robocopy ie
robocopy "\\myserver\newlayout" "\\myserver\oldlayout 20120511" /MIR
I just need to support this while we transition our folder structures.
Cheers
Aha I've solved it by looking at other answers.
set "myDate=%date:~6,4%%date:~3,2%%date:~0,2%"
robocopy "\\myserver\newlayout" "\\myserver\oldlayout %myDate%" /MIR
Even easier, you could do it with the single line:
robocopy "\\myserver\newlayout" "\\myserver\oldlayout %date:~6,4%%date:~3,2%%date:~0,2%" /MIR

robocopy /MIR - don't delete desktop.ini in destination

I want to sync folders between two computers, one with XP and one with Vista. I want the two folders mirrored, except for security settings and folder settings. It is my understanding that /MIR switch will delete any 'extra' files in the destination folder, which would include the desktop.ini files. I can avoid copying desktop.ini files with /XA:SH How can I prevent robocopy from deleting the destination desktop.ini files?
If I have to do any extra scripting, I prefer PowerShell. But I hope robocopy can do it on its own.
Thanks.
/XF desktop.ini
Will exclude Desktop.ini (from copy or purge).
Replace the /MIR switch with /E, and don't use the /PURGE parameter.
Explanation: /MIR is the equivalent of using /E /PURGE, so by using /E without /PURGE, you achieve the results you desire.
Create a bat file so you can mirror the source at the destination and later once the mirror process is finish erase the files you desired.
For example:
robocopy SOURCE DEST /E /PURGE or /MIR or /E
command to erase recursively (test the command before running at production):
del /s DRIVe:\DESTINATION\desktop.ini
Hope this helps,
Luis

Robocopy copy contents of current folder

How would you translate this xcopy command into Robocopy:
xcopy *.* "C:\DestinationFolder\"
Keeping in mind that the current folder where the command is run changes dynamically (and hence the source folder is unknown in advance).
Thanks.
robocopy . "c:\dest"
Note you don't need to specify a wildcard in robocopy, by default it copies everything unless you use the /xf /xd flags to exclude certain files.
Robocopy DOES support wildcards.
You're expecting > robocopy SOURCE DEST but type > robocopy *.txt c:\folderdest\ to copy the current folder. If you look at the output from robocopy it will show "Files : *.txt" and "Source = c:\folderdest"
So in fact you can do > robocopy WILDCARD SOURCE DEST. If you want to use the CURRENT folder you need to use . (as has been mentioned here). So you would use > robocopy *.txt . c:\folderdest\.
Screenshot: http://i.stack.imgur.com/Xyxt4.png
As an addition:
If robocopy is started from an administrator console, the current folder "." will point to Windows\system32.
You can use the following commands at the top of your batch file to fix this:
#setlocal enableextensions
#cd /d "%~dp0"