I'd like to be able to move Folders (and any subfolders and files) from one location to another; however, I only want one specific sub folder moved from each folder in the starting location.
Here's an example of my existing folder structure:
E:\Estimates\Estimating Files\E27001
E:\Estimates\Estimating Files\E27001\27001A - Customer1\Drawings
E:\Estimates\Estimating Files\E27001\27001A - Customer1\Costings
E:\Estimates\Estimating Files\E27001\27001B - Customer2\Drawings
E:\Estimates\Estimating Files\E27001\27001B - Customer2\Costings
E:\Estimates\Estimating Files\E27001\27001C - Customer3\Drawings
E:\Estimates\Estimating Files\E27001\27001C - Customer3\Costings
E:\Estimates\Estimating Files\E27002
E:\Estimates\Estimating Files\E27002\27002A - Customer1\Drawings
E:\Estimates\Estimating Files\E27002\27002A - Customer1\Costings
I have lots of estimates, as you can see some with the same number but a different suffix letter, and the Customer name obviously changes.
I want to move only the Drawings folders to a new drive and folder structure, like this:
S:\E27xxx\0xx\01\A - Customer1\
S:\E27xxx\0xx\01\B - Customer2\
S:\E27xxx\0xx\01\C - Customer3\
S:\E27xxx\0xx\02\A - Customer1\
The Drawings folders will have subfolders and files that I want moved across to the new location as well.
So far, I've only managed to create the empty folders up to this level:
S:\E27xxx\0xx\01\A - Customer1\
S:\E27xxx\0xx\01\B - Customer2\
S:\E27xxx\0xx\01\C - Customer3\
S:\E27xxx\0xx\02\A - Customer1\
using a small batch file, for all estimates from 27000 to 30000.
But moving the files and folders is beyond my capabilities, hopefully someone will be able to help me out Or know of an existing utility that might work!
Thanks!
Answer
I want to move only the Drawings folders to a new drive and folder
structure, like this:
This batch file could help you. It finds all the "Drawings" subfolders, it tokenizes the parts of the directory paths to construct the new directory struct, then copies each found directory with subdirectories using RoboCopy tool.
VERY IMPORTANT:
Ensure to place the batch file inside "...\Estimating Files" folder and run it from there, otherwise, manually set the
sourceDirvariable.Before use this script, you should manually adjust the token count of the
Forloop.For example, I used this source folder
C:\Source\Estimates\Estimating Files, we need to miss the first four tokens because we want to start counting after theEstimating Filespart, thats why I setTokens=4,5,6in the script below, if you have a different path then you should adjust the tokens.If your source dir is
E:\Estimates\Estimating Filesthen you should set the tokens parameter like this:Tokens=3,4,5.If want to automatically delete the copied source structure, just append a
/Movein the RoboCopy parameters.
Source-code
@Echo OFF
Set "sourceDir=%CD%"
Set "targetDir=C:\Target"
Set "findPattern=Drawings"
For /F "Tokens=4,5,6 Delims=\" %%a In (
'Dir /B /S /A:D "%sourceDir%\*%findPattern%"'
) Do (
Call Set "Token1=%%~a"
Call Set "Token2=%%~b"
Call Set "Token3=%%~c"
Call Set "sourcePath=%CD%\%%~a\%%~b\%%~c"
Call Set "targetPath=%targetDir%\%%Token1%%\%%Token1:~3%%\%%Token2:~3,2%%\%%Token2:~5%%\%%Token3%%"
Echo+
Call Echo Source: "%%sourcePath%%"
Call Echo Target: "%%targetPath%%"
(Call RoboCopy.exe "%%sourcePath%%" "%%targetPath%%" /E /ZB /COPYALL)1>Nul
)
Pause&Exit /B 0
Output
Source: "C:\Source\Estimates\Estimating Files\E27001\27001A - Customer1\Drawings"
Target: "C:\Target\E27001\001\01\A - Customer1\Drawings"
Source: "C:\Source\Estimates\Estimating Files\E27001\27001B - Customer2\Drawings"
Target: "C:\Target\E27001\001\01\B - Customer2\Drawings"
Source: "C:\Source\Estimates\Estimating Files\E27001\27001C - Customer3\Drawings"
Target: "C:\Target\E27001\001\01\C - Customer3\Drawings"
Source: "C:\Source\Estimates\Estimating Files\E27002\27002A - Customer1\Drawings"
Target: "C:\Target\E27002\002\02\A - Customer1\Drawings"
No comments:
Post a Comment