清除指定目录下所有文件和目录的bat脚本

Posted on 2010-07-23 11:05  名号M  阅读(1305)  评论(0)    收藏  举报

这段时间不太忙,抽空学习了一下批处理的东西。编了个清除制定目录内容的小程序,备忘

 

代码
@echo off
setlocal

rem set enviroment variable
set dir="e:\bat files\script\test"
rem clear all files under the directory
rem
 del %dir%\*.* /s/q

rem clear all the subdirectories
dir %dir/> dir.txt
for /"tokens=* usebackq" %%i in (dir.txt) do (
rd "e:\bat files\script\test\%%i"
)
echo all files and directories have been clear!
endlocal

 

 

博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3