xxcopy to exclude specific client folders and subfolders

Posted on 2014-02-04
Last Modified: 2014-02-05
Let's say I have a client folder path as follows:

F:\Clients\A\ABBIWJ-Abbolt, John T\
F:\Clients\A\ABS650 - ABS 6500, Inc\
F:\Clients\A\ACKLJB-Ackenlin, Josh B\
F:\Clients\A\ACMSCA - ACMS Corp\
F:\Clients\A\AERRES-Aerial Resolution\
F:\Clients\A\ALLEBM - Allen, Brook M\

The above displays a very small sample of the "A" folder client files.  Each letter (Clients\A\ - Clients\Z\) could have hundreds of clients folders.  The folder names begin with a six character client code followed for a "-" or spaces before and after the hyphen, and then the clients name (individual or business name).  The uniqueness is derived by the first six characters for the client folder name.  Within each client folder there will exist varying subfolders and files.

I am looking at about 10,000 client folders in total, and moving about seventy-five percent of the client folders to an archive location leaving the active client folders intact.  

I would like to create an exclusion file with only the six character client code (ABBIWJ,ABS650,ACKLJB...), so that an xxcopy command will move the other folders (in this case: ACMSCA,AERRES,ALLEBM).  The command should move these client folders along with all of its subfolders and files.  

The destination will be a NAS server, such as \\NAS01\Clients\A\

Question:  How can I have xxcopy look at the first six characters of the root client (Clients\A\ - Clients\Z\) folder name, compare the six characters with the list defined in the exclusion list, and if it does not exist in the list to move the folder/subfolders/files to the NAS storage device maintaining the same folder structure.  

I have not thought about the situations where a folder needs to be moved to the NAS storage device and the same client code folder name exists there as well, and should it simply replace it or add 1 after the destination name or simply merge it or something.  That will be the next issue after figuring out the above first.  Feedback is definitely appreciated.  

Thank you.
Question by:cmp119
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
LVL 54

Expert Comment

by:Bill Prew
ID: 39834589
I think this should get pretty close.  You will want to use ROBOCOPY since you are doing a move of the directories.  There may be some other options you want to explore there, but this should be a good start.  For testing the ROOCOPY line is preceded with ECHO, so when you run a test it won't move anything, just show the command that would execute.  Remove the ECHO if it looks good and rerun.  Adjust the SET lines at the top after creating your exclude file.

@echo off
setlocal EnableDelayedExpansion

REM Define from and to folders, and list file of folders to exclude
set FromDir=c:\ee\EE28356501\FROM
set DestDir=c:\ee\EE28356501\TO
set ExcludeFile=c:\ee\EE28356501\exclude.txt

REM Loop through all folders in base directory (these should be A - Z)
for /d %%A in ("%FromDir%\*.*") do (
  REM Loop through each folder with this A - Z folder
  for /d %%B in ("%%~A\*.*") do (
    REM Get just the folder name (no path, no extension)
    set DirName=%%~nB
    REM Search for the left 6 characters of folder name in exclude list
    find /c /i "!DirName:~0,6!" < "%ExcludeFile%" >NUL || (
      REM Not in exclude list, so go ahead ahnd move
      ECHO robocopy "%%~B" "%DestDir%\%%~nxB" /e /move

Open in new window


(edit: added comments)

Author Comment

ID: 39836322
We purchased xxcopy so that we can copy to UNCs just for this purpose.   Actually being able to copy/move data to network servers.  I just want clarification about this.  Thanks.
LVL 54

Expert Comment

by:Bill Prew
ID: 39836470
Sorry, I completely missed the extra "x" in xxcopy, thought you had proposed xcopy.  I also use xxcopy for some tasks, with that in mind let me see if I can revise the script to use xxcopy.

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!


Author Comment

ID: 39836613
You actually helped me in the past with a similar xxcopy task a couple of years back.  We are still using it to this day.  

I also need to mention, I normally run each letter individually (F:\Clients\A, F:\Clients\B...) since we are dealing with so many client folders\subfolders\etc.  It's also easier reviewing the log file for each letter as well.

Within each letter folder there are many client folders.  Each client folder should begin with a six character client code (ex:  \Clients\A\ABCDEF-ABCD Environment Functions).  I will have a client exclusion file that will only have the client code (ex: ABCDEF).  Not sure if the exclusion file needs the whole path for each client folder.  Will investigate that as well.

Anyway, if the client code (ABCDEF...) in the exclusion list is the same as the first six characters of the folder name, then it should "not" be moved.  Some client folders do not even have the folder names beginning with the client code, and they should be moved as well.  If the client folder name (beginning six characters of folder name) do  not match any of the client codes in the exclusion list, then it should move the folder and all of its subfolders and files to the specified destination maintaining the same folder structure.  

I still do not know how client folders that exist on the NAS and source location are handled (merged, overwritten, or creating a new folder but adding a number 1 at the end of the name so that they reside along side one another.  I will need to find out how that should be handled.  It might just be they want the information merged, and if the file exists with the same name in the same folder then it not "not" be overwritten, and simply adding 001 to the end of the file name (not file extension, we want that intact).  I think that's safer and a better approach.
LVL 54

Accepted Solution

Bill Prew earned 500 total points
ID: 39836700
Okay, I did a test here, and you should be able to do it all with one XXCOPY command, and the exclusion file.  I did a test using this command:

xxcopy "c:\ee\EE28356501\FROM\" "c:\ee\EE28356501\TO\" /E /RC /EXexclude.txt

Open in new window

and this "exclude.txt" file:


Open in new window

I had an A folder under the FROM folder.  It skipped those subfolders and copied the others.

If you were to do just a single letter at a time then I think it would look like this:

xxcopy "c:\ee\EE28356501\FROM\A\" "c:\ee\EE28356501\TO\A\" /E /RC /EXexclude.txt

Open in new window

and this "exclude.txt" file:


Open in new window


Author Closing Comment

ID: 39837129
bp -

Worked like a charm.  Once again thank you kindly for all your expertise!!!
LVL 54

Expert Comment

by:Bill Prew
ID: 39837475
Great, sorry I missed the xxcopy reference the first time around, it's a great tool when it can be leveraged.  Thanks for the feedback.


Featured Post

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

I use more than 1 computer in my office for various reasons. Multiple keyboards and mice take up more than just extra space, they make working a little more complicated. Using one mouse and keyboard for all of my computers makes life easier. This co…
Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

726 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