Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Batch file to move all subfolder files up then delete empty subfolders?

I have a folder that contains many subfolders, each with different files in them:

C:/folder/subfolder1/file1.jpg,
C:/folder/subfolder2/file2.jpg,
C:/folder/subfolder3/file3.jpg, 
etc.

How can I create a batch file that moves the files in the subfolders to the folder, then deletes the empty subfolders.

ie. After the bat file is run, the folder structure should be as follows:

C:/folder/file1.jpg
C:/folder/file2.jpg
C:/folder/file3.jpg 
etc.
like image 817
user2611836 Avatar asked Dec 26 '22 14:12

user2611836


1 Answers

try this

@echo off
for /f "tokens=*" %%f in ('dir /a:-D /s /b') do move "%%f" .
for /f "tokens=*" %%f in ('dir /a:D /s /b') do rd "%%f"
like image 106
rostok Avatar answered Jan 22 '23 12:01

rostok