Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Robocopy does not copy the root folder and its time stamp - it copies all subdirectories and files (when the appropriate options are set) and there seems to be no option/argument to tell Robocopy you want the root folder itself and its time stamp or attributes to be copied verbatim also.

So say I want I want to copy C:/Brushes

Robocopy will copy all its subdirectories and files into the destination, but not the Brushes folder itself, with all associated attributes and time stamp.

You understand what I am asking? This is pretty basic and Robocopy seems to lack a option for it. People have posed the question before in various forums but as far as I'm concerned, no one has answered the question.

enter image description here

share|improve this question
1  
This is a flyer, based on my experience with rsync, but what if you don't have a trailing slash at the end of your target folder? How about trying to modify the script at command-line level instead of using the GUI? I know for a fact that the command-line tool will do what you need. – user3463 Jan 18 '12 at 5:07
    
@Randolph West: presently I don't have a trailing slash at the end of the target folder. I still can't make Robocopy include the source folder and its attributes, etc. in the actual copy job. Any ideas? – ptrcao Jan 28 '12 at 17:19
    
If there is no solution for robocopy, you could have a look at xxcopy (there are freeware and commercial versions). – harrymc Jan 29 '12 at 16:16
    
Yep, I understand completely and have added a working solution below. The real problem is that you have to specify all the files and folders in the root NOT to copy. – opsin Jan 31 '12 at 0:09
robocopy %1 "C:\DestinationDirectory\%~n1" /E /V /DCOPY:T /LOG:"C:\DestinationDirectory\Copied.txt" /R:10 /W:30 

Drop a folder onto the bat or use in Send To. It will create folder with name & time stamp of source directory and copy all files.

share|improve this answer
    
thank you very much, was searching for that magic %~n1 operator – hotzen Sep 7 '13 at 11:13
    
@hotzen, What does the %~n1 do? – Pacerier Apr 25 '15 at 7:05
1  
They are listed here: microsoft.com/resources/documentation/windows/xp/all/proddocs/… – hotzen Apr 25 '15 at 16:26
    
"Expands %1 to a file name." – hotzen Apr 25 '15 at 16:27

Try md D:\Backup\Brushes && robocopy C:\brushes D:\Backup\Brushes from the command-line, substituting the correct paths.

share|improve this answer
1  
Yeah, but you are creating a new folder which will not have the attributes of the original C:\brushes folder...? – ptrcao Jan 28 '12 at 17:18

I agree with the OP, not being able to copy the root folder is a big shortcoming of robocopy. How about cheating and moving the brushes folder into a temporary folder, performing the robocopy operation on the temporary folder, then moving it back?

Something like:

md "c:\verytemporary" && move "c:\brushes" "C:\verytemporary"||( echo Line 1 error occurred & goto :eof )
robocopy c:\verytemporary d:\ /MIR /DCOPY:T
move "c:\verytemporary\brushes" "c:\" && rd /q "c:\verytemporary"||echo Line 3 error occurred
share|improve this answer

user105198's answer is the half way,

D:\Backup\Brushes && robocopy C:\brushes D:\Backup\Brushes will indeed just create a new folder. You will need to append /MIR and /DCOPY:T to it

With the /mir option, if the destination directory exists, the destination directory security settings are overwritten. Technet

/DCOPY:T :: COPY Directory Timestamps.

combined together, means : the source directory's attributes and timestamps will be mirrored to the created folder.

so:

D:\Backup\Brushes && robocopy C:\brushes D:\Backup\Brushes /MIR /DCOPY:T
share|improve this answer

As I can see no good and easy solution in any of the answers :

If there is no solution for robocopy, you could have a look at xxcopy (there are freeware and commercial versions).

There are of course many other alternatives to robocopy, some are listed here.
See also Best Free File Copy Utility.

share|improve this answer
    
xxcopy is a great utility, but the freeware version has a prompt that you must respond to if you using any of a large list of command line switches. Using xxcopy from a command window, this extra prompt is irritating. But it prevents (complicates) use of xxcopy from a batch file at all. – Kevin Fegan Jan 29 '14 at 22:11

I think you'll find that Robocopy does exactly what you want, provided you tell it to copy folder timestamps (/DCOPY:T). From my experiments, I've found the following (seemingly undocumented) behavior to be true for Robocopy:

All specified properties of the source directory are applied to the destination directory, regardless of whether the destination directory exists, doesn't exist, or has a different name from the source directory.

The specified properties can include (at least) the security information (/SEC) or folder timestamps (/DCOPY:T).

Therefore, in the following example, c:\destination\folder will be assigned the same timestamps as c:\source\folder.

robocopy c:\source\folder C:\destination\folder /E /DCOPY:T

I tested this with the versions of Robocopy included with Windows 7, Windows 8, and the Windows 2003 Resource Kit (/SEC parameter only). Note that only newer versions of Robocopy (XP026 and above) support the /DCOPY:T parameter.

share|improve this answer

If you combine /IF :: Include the following Files. with /E :: copy subdirectories, including Empty ones. you get (close to) the desired effect:

C:\Temp\Robocopy Source Root>robocopy . "C:\Temp\Robocopy Destination" /E /IF "Brushes*"
share|improve this answer
1  
What do you mean "close to"? What is the limitation you are implying? – ptrcao Jan 31 '12 at 0:14
    
Danger Will Robinson!!! Your suggestion seems to copy every folder in the current folder, not limit it to the folders beginning with "Brushes" – GlennFromIowa Nov 27 '13 at 15:24

Robocopy isn't really designed to do that easily. However, there is a way.

Root folder contains lets say 50 files and 40 folders. You only want folder X (but you also want it's time and date stamp).

ROBOCOPY c:\ d:\ /XF 50 root file names c:\boot.ini c:\bla.txt etc. /XD c:\windows c:\drivers c:\temp etc. /S /E /SEC /DCOPY:T

The /DCOPY:T tells it to keep the folder time stamps. The /XF specifies which files NOT to copy, /XD specifies which folders to NOT copy. Just don't specify folder c:\X.

The main drawback to this is researching all the folders and file names in the root and specifically calling them all here. If you are doing this a lot on different systems a script could be written.

Working Example

robocopy c:\testing c:\abc /XF c:\testing\Testing.txt /XD "C:\testing\New Folder (2)" "C:\testing\New Folder (3)" /S /E /SEC /DCOPY:T

Root Working Example

robocopy c:\ d:\ /XF c:\Testing.txt /XD "C:\New Folder (2)" "C:\New Folder (3)" /S /E /SEC /DCOPY:T

My test worked, I create a few folders and sub folders, c:\testing was root in this case, c:\abc was root of another drive (obviously they aren't really, but for this purpose it should make sense). The folder I wanted from the root was called "New Folder", as you can see I did not specify it in the /XD. Also, make sure you specify the c:\ or the names you use will be global. In other words if I didn't specify c:\testing in from of the Testing.txt file, it would omit it from ALL of the subfolders being copied. The /SEC will copy all the file security and time stamps.

share|improve this answer
    
Hmmm, I suppose you could use /XF c:*.* to exclude all the root files. I'll test that when I'm in front of a machine and not on a phone. – opsin Jan 29 '12 at 7:28
    
Nope, c:*.* is invalid, you'll have to manually list all of the files. – opsin Jan 29 '12 at 19:34

In theory, using /DCOPY:T should solve all your problems.

But, I've seen this happen, and I'm not sure I'd call it a "bug", but rather a consequence of the sequence of operations (OK, bug).

This command should work to copy all files from C:\Brushes to D:\NEWBrushes, and /DCOPY:T should cause the timestamps of the source folder to be copied to the destination folder:

robocopy "C:\Brushes" "D:\NEWBrushes" /COPY:DAT /DCOPY:T

What I've seen (at least on some versions of Robocopy) is that the command succeeds, but the timestamp of the D:\NEWBrushes folder is set to the current date and time.

So it appears that the /DCOPY:T feature does not work for the "base" (topmost) folder you are copying.

I believe that it is working, but that the timestamp of the destination folder is being "stepped on" by operations that are later in the operation sequence.

What I believe is happening for this command:

robocopy "C:\Brushes" "D:\NEWBrushes" /COPY:DAT /DCOPY:T

is something like this:

  1. Create folder D:\NEWBrushes if it doesn't already exist
  2. Copy the timestamp from C:\Brushes to D:\NEWBrushes
  3. Copy files and sub folders from C:\Brushes to D:\NEWBrushes

It appears that Step 3, the modification of the contents of the folder D:\NEWBrushes causes the timestamp of D:\NEWBrushes to change.

For me, the "workaround" has been to run the robocopy command to copy the files and folders, then run the (same) robocopy command a second time.

So, the first time you run:

robocopy "C:\Brushes" "D:\NEWBrushes" /COPY:DAT /DCOPY:T

all the files and folders will be copied. Then running it again:

robocopy "C:\Brushes" "D:\NEWBrushes" /COPY:DAT /DCOPY:T
  (or)
robocopy "C:\Brushes" "D:\NEWBrushes" /DCOPY:T

The second time robocopy runs, no files or folders within D:\NEWBrushes will be modified, and the /DCOPY:T option will tell robocopy to copy the timestamp from C:\Brushes to D:\NEWBrushes (unless there are folders/files in C:\Brushes that have changed since the first run of robocopy).

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .