Solved

# xxcopy to exclude specific client folders and subfolders

Posted on 2014-02-04
540 Views
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.
0
Question by:cmp119
[X]
###### 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
• 4
• 3

LVL 55

Expert Comment

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

~bp

0

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

LVL 55

Expert Comment

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.

~bp
0

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

LVL 55

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

and this "exclude.txt" file:

*\ABBIWJ*\
*\ABS650*\
*\ACKLJB*\

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

and this "exclude.txt" file:

ABBIWJ*\
ABS650*\
ACKLJB*\

~bp
0

Author Closing Comment

ID: 39837129
bp -

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

LVL 55

Expert Comment

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.

~bp
0

## Featured Post

Question has a verified solution.

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

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
In this post we will learn different types of Android Layout and some basics of an Android App.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…