[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

ROBOCOPY, folders, and wildcards : Files AND folders that begin ONLY with certain letters!

Posted on 2011-04-23
8
Medium Priority
?
17,454 Views
Last Modified: 2012-05-11
I want to copy everything beginning with the letter A or B over to the root of drive L:. That's it - AS SIMPLE AS THAT. Robocopy copies only the files, and won't touch the folders... Robocopy sure ain't lookin' robust to me. Prove me wrong!

More details for those who like details
--------------------------------------------
Version XP010 used on Windows 2000 Server
the command I used to successfully copy EVERYTHING (not my objective):
robocopy <source dir> L: /COPYALL /E /R:3 /W:5 /ZB /V /FP /LOG:testcopy.log

Open in new window


the command that has not been working for me to get everything starting with the letter "A":
robocopy <source dir> L: a*.* <with the same options as above> 

Open in new window

The result was that I only copied files starting with "a". All the folders beginning with A were untouched.

Will I have to do an /XD with c* d* e* f*.... all the way to z??? This might be the answer. I suppose sometimes we get the answers after taking the effort and time to form the question. If you have a better idea, plz let me know, or if you think that using /XD like this is it, plz let me know that also. Thx.

I know there are alternatives like RichCopy, but I can use only robo at the moment since it works after being copied onto the server (doesn't require installation). I need something fairly reliable since I have to preserve permissions also because I can't have the copy die in the middle leaving me clueless about what went and what didn't.


0
Comment
Question by:T-Dev
  • 4
  • 4
8 Comments
 

Author Comment

by:T-Dev
ID: 35453439
Please consider that I need to exclude files that have numbers as names also. Thx.
0
 
LVL 85

Accepted Solution

by:
oBdA earned 2000 total points
ID: 35453514
The third argument is indeed a *file* mask, not a folder mask. Robocopy just looks at the files and creates the folders as needed. Unfortunately, there is no "Include Directory" option, so you can only work with XD.
Another option might be to just create a batch wrapper script that kicks off separate robocopy jobs for the folders.
But it's not quite clear which files you actually want to copy: what happens with files that do NOT start with "a" or "b", but are inside a folder that starts with "a" or "b"?
And since you're writing to a log file, add /NP to your options; it keeps the control characters from the progress indicator out of the log.
0
 

Author Comment

by:T-Dev
ID: 35453588
I'm glad you brought up the issue of files within folders... I want EVERYTHING inside the folders to get copied. So, the idea of using a*.* b*.* looks like a mistake!! - because it excludes lots of files within the folders getting copied. Argh! So, without a*.* b*.* my command now looks like this:

robocopy H: L: /E /COPYALL /R:3 /W:5 /ZB /V /FP /LOG:test.log /XD c* d* e* f* g* h* i* j* k* l* m* n* o* p* q* r* s* t* u* v* w* x* y* z* 1* 2* 3* 4* 5* 6* 7* 8* 9* 0*

Open in new window


However, now, the unwanted result is that while I successfully copy only folders with names starting with A or B, I end up copying all files from the root of my source as well.

I have an untested solution for copying all files on the root of H: that begin with A or B:. It consists of using a*.* b*.* /XD *.*. But what about the other situation --> How to copy just folders beginning with A or B with ALL their contents AND exclude all files on the root of H:? You see, I have big files on the root of H: beginning with other characters, and waiting for them is not an option.

So, using the robo command twice would be ok. I just don't know how to exclude all files while copying all of the files inside the folders. Thx.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 85

Assisted Solution

by:oBdA
oBdA earned 2000 total points
ID: 35453629
Here's a little batch script that will run one robocopy job for the files in the root of the drive, and then create separate robocopy jobs for all folders in the source starting with a or b.
@echo off
setlocal enabledelayedexpansion
set Source=H:
set Target=L:
set CopyOptions=/COPYALL /R:3 /W:5 /ZB /V /FP /LOG+:testcopy.log
REM Copy all files starting with a or b in the root of the source folder:
robocopy.exe "%Source%" "%Target%" a*.* b*.* %Options%
REM Copy all folders starting with a or b in the source folder:
for /d %%a in ("%Source%\a*" "%Source%\b*") do (
  robocopy.exe "%%a" "%Target%" /E %Options%
)

Open in new window

0
 

Author Comment

by:T-Dev
ID: 35453775
That's sophisticated. It appears to acknowledge robocopy's limitations as I perceived them.

I see what it does. The first time the robocopy command is issued, it's done without /E or /S, which is why it does just files.

Then DOS handles the wildcard for folders, changing the source again and again, and creates a new robocopy command for each different source since Robocopy doesn't appear able to handle wildcards in the <source> or <dest>.

A minor quibble is that it looks like each folder's contents are sent as files, not as folders. So, L: would become populated with the files, not the folders with the files within them. This is a minor because you really have presented a solution that I think would work with the challenge I presented. The quibble could be solved by adding a line to create the dirs and then use them as destinations. Any other ideas?
0
 
LVL 85

Expert Comment

by:oBdA
ID: 35454138
Sorry, yes, that can of course be done as well.
Just replace line 10 with this (adds "\%%~nxa" after %Target%):
 robocopy "%%a" "%Target%\%%~nxa" /E %Options%

Open in new window

0
 

Author Comment

by:T-Dev
ID: 35460365
2 important comments to add (to give oBda credit, help others, and document this for my own benefit - cuz I'll most likely forget it!! hehe)

1. First of all, oBdA, your last comment was also very useful because I had no idea what %%~nxa was until I realized (after googling) that it's just our %%a again with this ~nx shoved in the middle. It still wasn't clear why this was needed; so I did a test, and saw that ~nx trimmed a folder's path name down from its long path (like c:\rootfolder\nextfolder\anotherfolder\finallythefoldername.yep) to just its Name and eXtension, which comes out to finallythefoldername.yep.

2. Secondly, above, I thought that /XD would do the job if I used it like this: robocopy blah blah /XD c* d* e* f* g* h* i* j* k* l* m* n* o* p* q* r* s* t* u* v* w* x* y* z* _* 0* 1* 2* 3* 4* 5* 6* 7* 8* 9*. The good part of this plan is that it does successfully exclude all directories beginning with letters other than A and B. HOWEVER, the bad part is that it continues to do that inside the folders beginning with A and B as well! Argh!!

So, it truly appears that the DOS batch file is the only approach that succeeds in producing the desired result.
0
 
LVL 85

Expert Comment

by:oBdA
ID: 35460897
Yes, %%~nxa will expand to name and extension of the path in %%a; enter "help call" in a command prompt for details.
And, yes, robocopy is very thorough; if you only want to the exclude root dirs beginning with certain characters, try specifying full paths: "/XD H:\c* H:\d* ..."
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

My purpose is to describe the basic concepts of virtual memory as implemented in a modern Windows-based operating system. I will also describe the problems inherent in older systems and how virtual memory solves them. The dark ages - before virtu…
Citrix XenApp, Internet Explorer 11 set to Enterprise Mode and using central hosted sites.xml file.
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question