Remove subfolders from a folder (loop)

March 23, 2012 at 03:32:26
Specs: Windows 7
Hello,

I have a collection of folders which contain subfolders and files.

I want for each folder that contains subfolders to remove them but keep the files in this folder.

For exemple, from this :

Root folder
_folder 1
__subfolder 1
___test.txt
__subfolder 2
___test.jpg
_folder 2
__subfolder 1
___subsubfolder 1
____test.mov

I want this :

Root folder
_folder 1
__test.txt
_test.jpg
_folder 2
__test.mov

ps : I put underscore to see the "tree"

Thank you.


See More: Remove subfolders from a folder (loop)

Report •


#1
March 26, 2012 at 16:30:21
Run this inside your root folder.

@echo off
for /f "tokens=*" %%i in (
'dir /b /a:d'
) do (
pushd .
cd %%i
for /f "tokens=*" %%z in (
'dir /s /b /a:-d'
) do (
move "%%z" . >nul
for /f "tokens=*" %%t in (
'dir /b /s /a:d'
) do (
rd /q "%%t" >nul 2>nul
)
)
popd
)

Tony


Report •
Related Solutions


Ask Question