China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-06 01:58
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Help] Question for the moderator about a batch file problem extracting files from folders! View 888 Replies 3
Original Poster Posted 2007-10-10 23:40 ·  中国 重庆 电信
初级用户
Credits 70
Posts 33
Joined 2007-06-03 21:10
19-year member
UID 90174
Gender Male
Status Offline
For example, inside one folder there are 100 folders, and each folder has subfolders and files in it. How can I extract all the files from all the subfolders inside that main folder into that main folder, and then delete all the subfolders inside the main folder (for example, if the files are images or text files)?
Floor 2 Posted 2007-10-11 00:01 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline
@echo off
for /f "delims=" %%a in ('dir /s /b /a-d *.jpg *.txt') do (
if exist ".\%%~nxa" (echo File %%~nxa is duplicated) else (
move "%%~a" .\
)
)
for /f "delims=" %%a in ('dir /s /b /ad *^|sort /r') do rd "%%~a" 2>nul
echo Processing is finished...press any key to exit...&pause>nul

Put this batch file in the main folder to be processed and run it there.
Floor 3 Posted 2007-10-11 00:12 ·  中国 重庆 电信
初级用户
Credits 70
Posts 33
Joined 2007-06-03 21:10
19-year member
UID 90174
Gender Male
Status Offline
Test succeeded. I really admire you, boss.
Floor 4 Posted 2007-10-13 11:22 ·  中国 江西 南昌 电信
中级用户
★★
Credits 245
Posts 123
Joined 2007-06-08 09:04
19-year member
UID 90636
Gender Female
Status Offline
Learning
Forum Jump: