Declaration: The codes on floors 1 and 2 run under the XP sp2 environment.
Because of work needs, I have to create many directories named with the current date every day in the working directory (each subdirectory may be created), but sometimes it is inevitable that after creating a directory, I don't put files in it. Over time, many empty directories will accumulate. It's impossible to delete them manually. So I want to use a batch script to do it, but I encountered a problem:
The program can't handle directories with special characters or spaces correctly.
Here I ask some experts in the forum who are good at for and findstr to see if there is any good way.
[ Last edited by voiL on 2006-12-26 at 04:33 AM ]
Because of work needs, I have to create many directories named with the current date every day in the working directory (each subdirectory may be created), but sometimes it is inevitable that after creating a directory, I don't put files in it. Over time, many empty directories will accumulate. It's impossible to delete them manually. So I want to use a batch script to do it, but I encountered a problem:
The program can't handle directories with special characters or spaces correctly.
Here I ask some experts in the forum who are good at for and findstr to see if there is any good way.
::***/// Set the target directory \\\***
set keyword1=m:\test\
::***/// Set the folder names that need to be deleted (because some folders don't want to be deleted) \\\***
set keyword2=2006-12-
::***/// Create temporary files and directories \\\***
cd.>nuldir.txt
cd.>nuldir2.txt
md 目录回收
::***/// List all directory names in the current directory and output to nuldir.txt \\\***
for /f "delims=" %%i in ('dir /ad /b /s') do (dir /a /b "%%i"|findstr .>nul||echo %%i>>nuldir.txt)
::***/// Exclude directories with specified conditions in nuldir.txt and write to nuldir2.txt \\\***
for /f "delims=%keyword1% tokens=1*" %%i in (nuldir.txt) do echo %%j>>nuldir2.txt
type nuldir2.txt | findstr /i "%keyword2%">nuldir.txt
::***/// Create new directories under "Directory Recycling" and delete the original directories \\\***
for /f %%i in (nuldir2.txt) do md 目录回收\%%i && del /q %%i
::***/// Delete temporary files \\\***
del /q nuldir.txt & rd /q nuldir2.txt
[ Last edited by voiL on 2006-12-26 at 04:33 AM ]
