13

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

4
  • 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
    Commented Jan 18, 2012 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
    Commented Jan 28, 2012 at 17:19
  • If there is no solution for robocopy, you could have a look at xxcopy (there are freeware and commercial versions).
    – harrymc
    Commented Jan 29, 2012 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
    Commented Jan 31, 2012 at 0:09

11 Answers 11

10
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.

6
3

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
2

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

1
  • 4
    Yeah, but you are creating a new folder which will not have the attributes of the original C:\brushes folder...?
    – ptrcao
    Commented Jan 28, 2012 at 17:18
2

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.

1
  • 1
    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. Commented Jan 29, 2014 at 22:11
1

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
1

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.

0

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*"
2
  • 1
    What do you mean "close to"? What is the limitation you are implying?
    – ptrcao
    Commented Jan 31, 2012 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" Commented Nov 27, 2013 at 15:24
0

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.

2
  • 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
    Commented Jan 29, 2012 at 7:28
  • Nope, c:*.* is invalid, you'll have to manually list all of the files.
    – opsin
    Commented Jan 29, 2012 at 19:34
0

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).

0

I was solving the root folders right now for one really quick and easy backup script with robocopy, there is an example. Should help to anyone:

$Destination="F:\Backup" #change destionation backup drive and foder
$BackupDirs="d:\folder1", "d:\folder2", "d:\folder3\subfolder", "d:\fodler4\subfolder\subsubfodler" #change source folders

#make a loop for every source folder
foreach ($Backup in $BackupDirs) {

#split folder name
$fdname = Split-Path $Backup -leaf

#define folder to create in destionation
$dirtocreate = Join-Path $Destination $fdname

#make directory, yes, some extra script to skip when exist should be in place, but -erroraction solved this in lazy mode :)
md $dirtocreate -ErrorAction SilentlyContinue 

#copy with subfolders and log
robocopy $backup $dirtocreate  /s /nfl /ndl /log:c:\scripts\backup.log

}
1
0

I have to copy more than 100 folders from one file server to another, In that case, I faced kind of the same problem.

I will share my experience with you, maybe this might help you -

Suppose, (you want to copy folderB from Source to Destination ) -

you have - \Source\folderA\folderB

you want - \Destination\folderB

In that case, what I did is, first of all, I find out the lowest level directory name from the source path, Which is (folderB) is my case-

$source = "\\Source\folderA\folderB" 
$destination = "\\Destination\"
$FileName = Split-Path $source -Leaf    #output will be "folderB"

Now, I will use robocopy for copying the directory and all its subdirectories and files.

robocopy "$source" "$destination\$FileName" /DCOPY:T /e 

/DCOPY:T - copy the timestamp of the directory

/e - Copies subdirectories. This option automatically includes empty directories.

You must log in to answer this question.

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