0

I have a directory that looks like this

Root Folder
  - Folder A
    - Subfolder
        - File1
        - File2
        - File3
  - Folder B
    - Subfolder
        - File1
        - File2
        - File3
  - Folder C
    - Subfolder
        - File1
        - File2
        - File3

Now I want to move the subfolder & files up by a level and delete the folder once it's been moved up so it should look like this

Root Folder
    - Subfolder
        - File1
        - File2
        - File3
    - Subfolder
        - File1
        - File2
        - File3
    - Subfolder
        - File1
        - File2
        - File3

Is there a batch method to do this in windows?

0

If there's a pattern for "Folder [a|b]" that doesn't duplicate in the names of "subfolders" then yes, this is a pretty simple batch script.

for /d %%d in ("folder*") do call :doit "%%d"
exit /b

:doit
@echo.Moving contents of "%~1" to "%cd%"...
pushd "%~1"
forfiles /c "cmd /c move @file .."
popd
@echo.Removing "%~1"
rd "%~1"
exit /b

Again, it's very important to understand that this requires a pattern to the folder names ("folder*"). If this replicates within your content folders then you will lose data.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.