0
votes

I have a directory structure which contains files organized into folders by an associated ID

..\abc\STORAGE\123
..\abc\STORAGE\234
..\xyz\STORAGE\345
..\xyz\STORAGE\456

I want all of the bottom subfolders, and all their contents, to be copied into a new directory such that afterwards I will have:

..\SomeNewDir\123
..\SomeNewDir\234
..\SomeNewDir\345
..\SomeNewDir\456

How should I accomplish this, using a batch script?

2
Your title says move and your question says copy so it is unclear.foxidrive

2 Answers

0
votes

Test this: launch it in the folder that holds the abc and xyz folders.

@echo off
for /d %%a in (*) do xcopy "%%a\storage\*.*" "c:\somenewdir\" /s/h/e/k/f/c
0
votes
@echo off
    setlocal enableextensions

    set "sourceRoot=%cd%"
    set "target=d:\test"

    for /r /d %%a in (*) do (
        set "bottom=1"
        for /d %%b in ("%%~fa\*") do set "bottom="
        if defined bottom (
            echo move "%%~fa" "%target%"
        )
    )

This will search the last directory in each sub branch of indicated source, independtly of name, and move (when the output to console is correct, remove the echo) the subdirectory to the target folder