Solved

xxcopy to exclude specific client folders and subfolders

Posted on 2014-02-04
7
497 Views
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.
0
Comment
Question by:cmp119
  • 4
  • 3
7 Comments
 
LVL 51

Expert Comment

by:Bill Prew
Comment Utility
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

~bp

(edit: added comments)
0
 

Author Comment

by:cmp119
Comment Utility
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 51

Expert Comment

by:Bill Prew
Comment Utility
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

by:cmp119
Comment Utility
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 51

Accepted Solution

by:
Bill Prew earned 500 total points
Comment Utility
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:

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

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:

ABBIWJ*\
ABS650*\
ACKLJB*\

Open in new window

~bp
0
 

Author Closing Comment

by:cmp119
Comment Utility
bp -

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

Expert Comment

by:Bill Prew
Comment Utility
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article will show, step by step, how to integrate R code into a R Sweave document
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
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 …

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now