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
  • 4
  • 3
LVL 53

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 53

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.

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!


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 53

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 53

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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

777 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