Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm looking for a solution to use robocopy to copy several folders from a directory onto a distant network share. I want to choose several folders out of a directory that contains hundreds of folders I'm not interested in. I want to do something similar to scp in linux using regex, but this doesn't work in robocopy:

c:\robocopy "c:\results\1319_TC1.*" "\\datastore\somefolder\"
share|improve this question

4 Answers 4

up vote 3 down vote accepted

Try this one:

gci C:\results\1319_TC1.* | foreach-object { robocopy $_.fullname (".\datastore\somefolder\" + $_.name) }

gci C:\results\1319_TC1.* get's all matching files/directories first and puts them through the pipe where foreach-object takes care of all results from the first command. It'll robocopy the fullpath of each result (full path to your result-directories) and put them into .\datastore\somefolder\ with its original foldername e.g.:
C:\results\1319_TC1.123456 -> C:\results\datastore\somefolder\1319_TC1.123456

That thing in braces will put that target-directory-name and the original folder-name together.

Edit:
I just saw that your target-directory should be a UNC-path. Robocopy accepts UNC-paths (even with path-names longer than 256 characters). You just have to replace (".\datastore\somefolder\" with ("\\datastore\somefolder\" in my command. So the right command would be:

gci C:\results\1319_TC1.* | foreach-object { robocopy $_.fullname ("\\datastore\somefolder\" + $_.name) }

share|improve this answer

You would do it in a batch file. You will need on line per directory.

In the alternative, you could do this, which would copy everything and then delete the excess if that is easier: Robocopy z:\directory d:\directory /MIR /COPYALL (Caution: MIR is for mirror image and will overwrite anything in its way, so use only on a blank directory).

share|improve this answer

You will not be able to do this with Robocopy alone. If you have access to a linux machine, it would be trivially easy using find with the -exec option. Or you could use cygwin on windows (I would guess it has the find command), or you could use a scripting language like Ruby or Python on Windows.

share|improve this answer
    
Linux or cygwin aren't neccessary since he has access to powershell which is able to use regex. However, this would work... –  wullxz May 23 '11 at 21:42
    
Yeah, of course these are not the only options, but they would be my top picks. –  James May 23 '11 at 21:45
    
Yeah, each to his own liking :) –  wullxz May 23 '11 at 21:51

A quick powershell like this:

$Dir = get-childitem "c:\results\"  -recurse
$List = $Dir | where {$_.FullName -match "1319_TC1."}
$List | split-path FullName -parent | get-unique

Will give you a list of all files that are in a folder that matches "1319_TC1." Then all you need to do robocopy each of those folders.

share|improve this answer

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.