Board logo

标题: [文件操作] [已解决]批处理如果删除所有盘下面的指定目录? [打印本页]

作者: ygqiang    时间: 2011-6-17 17:24     标题: [已解决]批处理如果删除所有盘下面的指定目录?

  1. for %%a in (c d e f g h i j k l m n o p q r s t) do (
  2. for /f "Delims=" %%i in ('dir /b "%%a:\FOUND*"') do ( rd /s /q "%%i")
  3. )
复制代码
如何修改这个批处理命令,

实现删除所有盘下面的,所有FOUND.000 FOUND.001 FOUND.002 FOUND.003 ....一直到FOUND.049等等这么多目录?

最好只修改循环里面的代码。谢谢
for /f "Delims=" %%i in ('dir /b "%%a:\FOUND*"') do ( rd /s /q "%%i")
作者: tmplinshi    时间: 2011-6-17 17:52

  1. @echo off
  2. for %%a in (c d e f g h i j k l m n o p q r s t) do (
  3.     for /f "delims=" %%i in ('dir /b /a:d %%a:\FOUND.*') do (
  4.         rd /s /q "%%a:\%%i"
  5.     )
  6. ) 2>nul
复制代码

作者: ygqiang    时间: 2011-6-17 18:27

多谢楼上。

代码可以运行。
作者: ygqiang    时间: 2011-6-17 18:29

本帖最后由 ygqiang 于 2011-6-17 19:37 编辑
  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\FOUND.000" rd /s /q "%1\FOUND.000" >nul 2>nul
  6. cls
  7. if exist "%1\FOUND.001" rd /s /q "%1\FOUND.001" >nul 2>nul
  8. cls
  9. if exist "%1\FOUND.002" rd /s /q "%1\FOUND.002" >nul 2>nul
  10. cls
  11. if exist "%1\FOUND.003" rd /s /q "%1\FOUND.003" >nul 2>nul
复制代码
类似这种代码,应该如何修改呢?
作者: tmplinshi    时间: 2011-6-17 18:49

你要说下你想要处理成什么结果。

楼上代码中的删除文件操作时多余的,直接删除文件夹即可;
直接判断 c d e f g h i j k l m n o p q r s t 这些盘符,比 wmic 的方法好;
作者: ygqiang    时间: 2011-6-17 19:38

就是想看看,用wmic这个方法,如何实现?
作者: tmplinshi    时间: 2011-6-17 19:48

这样?
  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. for /f "delims=" %%i in ('dir /b /a:d %1\FOUND.* 2^>nul') do (
  5.     rd /s /q "%1\%%i"
  6. )
  7. goto :eof
复制代码

作者: ygqiang    时间: 2011-6-17 20:06

嗯。多谢斑竹。

以上代码可以运行。




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