Home > OS >  How to make a script also copy a directory Tree with Batch
How to make a script also copy a directory Tree with Batch

Time:10-12

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

These are my folders, now I am keeping it short because I have more folders then what I have shared here, in the bread folder I have 20 more folders and in Wheat folder I have 15 more folders and I have more main folders thousands more

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

Here is my workstation

Grains.bat
Food Network
  ---- Bread
          --- Grains
                |-- data.pgt
          --- Corn
                |-- data.pgt
  ---- Wheat
          --- Grains
                |-- data.pgt
          --- Flour
                |-- data.pgt

Results
All Grains
  ---- Grains
         |-- data.pgt

Every Grains folder gets merged and data.pgt overwrites

My goal here is to get this result, and for it to focus on the Folder Name

My resluts
All Grains
  ---- Bread
          --- Grains
                |-- data.pgt
  ---- Wheat
          --- Grains
                |-- data.pgt

Here is my script

for /f "tokens=*" %%G in ('dir /b /s /a:d "Grains"') do move "%%G" "All Grains"

Right now I can only make the script MOVE the folders, I tested copy and it doesn't copy

this is the way to set up this script

@ECHO OFF
SETLOCAL

SET "sourcedir=%~dp0"
SET "destdir=%~dp0"

SET "tdnames="Food Network""

SET "leafnames="Grains""

SET "destsub="All Grains""

FOR %%T IN (           
  • Related