Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 592
  • Last Modified:

xxcopy to exclude specific client folders and subfolders

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
cmp119
Asked:
cmp119
  • 4
  • 3
1 Solution
 
Bill PrewCommented:
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
 
cmp119Author Commented:
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
 
Bill PrewCommented:
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
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 
cmp119Author Commented:
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
 
Bill PrewCommented:
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
 
cmp119Author Commented:
bp -

Worked like a charm.  Once again thank you kindly for all your expertise!!!
0
 
Bill PrewCommented:
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 Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now