Board logo

标题: [文件操作] 求教:全盘搜索指定文件夹删除其中的几类文件(目录) [打印本页]

作者: Nano    时间: 2010-1-14 20:33     标题: 求教:全盘搜索指定文件夹删除其中的几类文件(目录)

  1. ::刪除臨時文件
  2. for %%n in (cache temp tmp) do (
  3.   for /f "tokens=*" %%i in ('dir /ad /b /s %dest%\%%n') do rd /s /q "%%i"
  4. )
  5. del /a /f /q /s .\*.tmp
复制代码
下邊這段是抄來的請斑斑幫修改下谢谢  ^_^ 代碼已加框(本来是想修改完了再加的)
  1. @echo off
  2. for %%i in (c d e f g h i j k l m n o) do (
  3.     if exist %%i:\aaa.txt set drive=%%i&goto another
  4. )
  5. goto :eof
  6. :another
  7. echo aaa.txt位于 %drive% 分区
  8. command
复制代码

如:
C:\a b c\temp\11.tmp
d:\a b c\temp\12.tmp
e:\a b c\temp\13.tmp
如果C盘存在a b c文件夾刪除其中的Temp tmp 文件(目錄)
接下来如果D盘存在a b c文件夾刪除其中的Temp tmp 文件(目錄)
直到全盘
如果全盘无指定的文件夹。。退出BAT

完全的门外汉。。看了几天贴还是糊涂的紧。。

[ 本帖最后由 Nano 于 2010-1-14 20:49 编辑 ]
作者: Batcher    时间: 2010-1-14 20:39

  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 u v w x y z) do (
  3.     rd /s /q "%%a:\a b c\tmp" 2>nul
  4.     rd /s /q "%%a:\a b c\temp" 2>nul
  5.     del /s /q /f /a "%%a:\a b c\*.tmp" 2>nul
  6.     del /s /q /f /a "%%a:\a b c\*.temp" 2>nul
  7. )
复制代码

作者: Nano    时间: 2010-1-15 14:29     标题: 回复 2楼 的帖子

  1. ::搜索CloudCache
  2. set "Folder=CloudCache"
  3. set "Path=%%D:\%Folder%"
  4. for %%D in (C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
  5.     for %%n in (tmp temp cache) do (
  6.     for /f "tokens=*" %%f in ('dir /a /b /s "%Path%\*%%n*"') do (
  7. rd /s /q "%%f" && del /a /f /q /s "%%f" && echo 已刪除文件"%%f"
  8. ))) 2>nul
  9. CD %Path%
复制代码
斑斑我這個最後一句切換到%Folder%怎麼弄才好。。網上搜後說CD不支持帶盤符路徑。。
由于云端软件目录是随机机所能不能指定文件夹只能按特定的文件夹搜索后修改文件。。其是我是想在执行以上命令后进入到*:\CloudCache搜索JumpListIcons文件夾刪除Sa Brng Blm F e2 1無扩展文件。。

[ 本帖最后由 Nano 于 2010-1-15 14:41 编辑 ]
作者: Batcher    时间: 2010-1-15 17:32     标题: 回复 3楼 的帖子

path是系统默认变量,建议不要在代码中定义同名变量,改成mypath如何?
“網上搜後說CD不支持帶盤符路徑”,网上的大忽悠太多了!
  1. cd /d "%mypath%"
复制代码





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