I made a script that can copy certain folders
, but I would like for it to also copy the directory folders
where the folders were found
I know about Robocopy
and Xcopy
for my goal these script will not do the job because I would have to /XD
many folders and I have to many folders to type in every folder to the script
I want to Copy or Move Folder 2
Here is my workstation
Tester.bat
Main Storage Folder
+ ---- Folder A
+ --- Folder 1A
+ --- Folder 2
|-- data.pgt
+ --- Folder 3
|-- data.pgt
+ ---- Folder B
+ --- Folder 1B
+ --- Folder 2
|-- data.pgt
+ --- Folder 3
|-- data.pgt
My Goal Results
Backup Storage Folder
+ ---- Folder A
+ --- Folder 1A
+ --- Folder 2
|-- data.pgt
+ ---- Folder B
+ --- Folder 1B
+ --- Folder 2
|-- data.pgt
Here is my script
for /f "tokens=*" %%G in ('dir /b /s /a:d "Grains"') do move "%%G" "Folder 2"
Right now I can only make the script MOVE
the folders, I tested copy and it doesn't copy
When I run the script I get these results
@ECHO OFF
SETLOCAL
SET "sourcedir=%~dp0"
SET "destdir=%~dp0"
SET "tdnames="Main Storage Folder""
SET "leafnames="Folder 2""
SET "destsub="Backup Storage Folder""
FOR %%T IN (%destsub%) DO (
FOR %%t IN (%tdnames%) DO (
FOR %%s IN (%leafnames%) DO (
FOR /f "delims=" %%b IN ('dir /b /s /ad "%sourcedir%\%%~t\%%~s" 2^>nul') DO (
FOR %%c IN ("%%~dpb.") DO (
MD "%destdir%\%%~T\%%~nxc\%%~nxb" 2>nul
Xcopy "%%~b\*" "%destdir%\%%~T\%%~nxc\%%~nxb"
)
)
)
)
)
GOTO :EOF
My Goal Results
Backup Storage Folder
+ --- Folder 1A
+ --- Folder 2
|-- data.pgt
+ --- Folder 1B
+ --- Folder 2
|-- data.pgt
As you can see Folder A
and Folder B
are missing
My actual Workstation inside Main Storage Folder
I have over 60 different folders and inside those 60 folders I have at least 10 different folder, and inside each of those 10 folders I have repeated names for example Folder 2
so Folder 2 is found in each folder
I have tried 10 different ways to find a fix but nothing works, the closes I got was editing this line
FOR %%c IN ("%%~dpb..") DO (
I added an extra period, but now it skips Folders 1A and 1B and copies Folder A and B
Backup Storage Folder
+ ---- Folder A
+ --- Folder 2
|-- data.pgt
+ ---- Folder B
+ --- Folder 2
|-- data.pgt