Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
add comment

9 Answers 9

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
add comment

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

share|improve this answer
    
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
add comment

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
add comment

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
add comment

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 at 22:11
add comment

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
add comment

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
add comment

I don't have Robocopy available on this system to test, but try via command line:

robocopy C:\Brushes C:\Brushes.NEW C:\Brushes /S /E

It says here that it will take more than two file arguments, the third, etc. being "files to copy." Maybe if the directory is explicitly stated it will include it. I have never tried it.

You may also try using a wildcard that matches only that file in the first argument. This will require caution:

robocopy C:\Brushe? C:\Brushes.NEW /S /E

Again, not sure if that would work.

share|improve this answer
    
Nope, both of these syntaxes produce Invalid Parameter errors: the first on parm #3 and the second on parm #1. –  GlennFromIowa Nov 27 '13 at 15:23
add comment

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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.