Board logo

标题: [文本处理] [已解决]批处理怎样删除除C盘外所有盘下面的空目录? [打印本页]

作者: ygqiang    时间: 2011-6-26 13:23     标题: [已解决]批处理怎样删除除C盘外所有盘下面的空目录?

  1. ;删除所有盘下面的空目录(系统盘c盘除外)
  2. for %%a in (d e f g h i j k l m n o p q r s t) do (
  3. for /f "tokens=*" %%j in ('dir /s/ad/b %%a:') do rd "%%j" 1>nul 2>nul
  4. )
  5. cls
复制代码
这个代码,xp系统下运行,一般情况下不会出现问题。


但如果使用读卡器+SD卡(sd卡已经打开写保护开关),或者使用带写保护开关的u盘(u盘已经设置到写保护状态)

这种情况下,运行代码,就会弹出窗口。

如果实现不弹出窗口?
作者: CrLf    时间: 2011-6-26 13:45

wmic logicaldisk where access="0" get name /value
作者: ygqiang    时间: 2011-6-26 13:52

多谢啊。

wmic命令不太懂。
能否给出完整的代码,实现要求的功能??
作者: CrLf    时间: 2011-6-26 13:59

  1. for /f "tokens=2 delims=:" %%a in ('
  2.    wmic logicaldisk where access="0" get name /value
  3. ) do if "%%a" neq "" (
  4.    for /f "tokens=*" %%j in ('dir /s/ad/b %%a:') do rd "%%j" 1>nul 2>nul
  5. )
复制代码

作者: ygqiang    时间: 2011-6-26 14:09

以上代码,运行了,不行。
作者: Hello123World    时间: 2011-6-26 15:23

这个标题词不达意——其实是要操作写保护的移动盘。(这跟删除空文件有什么关系,写了保护你删除非空文件夹又删的掉了?)
作者: ygqiang    时间: 2011-6-26 15:39

  1. for /f "skip=1 delims=" %%a in ('Wmic LogicalDisk Where "DriveType='2' and SupportsDiskQuotas='FALSE'" Get DeviceID') do call :s1 %%a
  2. for /f "skip=1 delims=" %%a in ('Wmic LogicalDisk Where "DriveType='3'" Get DeviceID') do call :s1 %%a
  3. :s1
  4. if "%~1"=="" goto:eof
  5. if exist "%1\RECYCLER" rd /s /q "%1\RECYCLER" >nul 2>nul
  6. cls
  7. if exist "%1\Recycled" rd /s /q "%1\Recycled" >nul 2>nul
  8. cls
  9. if exist "%1\$RECYCLE.BIN" rd /s /q "%1\$RECYCLE.BIN" >nul 2>nul
  10. cls
  11. for /f "delims=" %%i in ('dir /b /a:d %1\FOUND.* 2^>nul') do (
  12.     rd /s /q "%1\%%i"
  13. )
复制代码
  1. ;删除所有盘下面的空目录(系统盘c盘除外)
  2. for %%a in (d e f g h i j k l m n o p q r s t) do (
  3. for /f "tokens=*" %%j in ('dir /s/ad/b %%a:') do rd "%%j" 1>nul 2>nul
  4. )
  5. cls
复制代码
以上这2个代码,能否配合下,实现:
1、不弹出窗口(如果SD卡或者u盘是写保护了的话)
2、能删除所有盘下面的空目录(系统盘c盘除外)?
作者: ygqiang    时间: 2011-6-26 16:23

解决了。。
  1. echo 删除所有盘下面的空目录(系统盘c盘除外)
  2. for %%i in (D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
  3. fsutil fsinfo drivetype %%i: | find "固定">nul && (
  4. for /f "tokens=*" %%j in ('dir /s/ad/b %%i:') do rd "%%j" 1>nul 2>nul
  5. )
  6. )
复制代码





欢迎光临 批处理之家 (http://www.bathome.net/) Powered by Discuz! 7.2