.bat 文件,用于选择性删除三个文件的 IE 缓存

.bat file for selectively deleting IE cache for three files

感谢您的帮助

我目前在处理删除专门针对这三个文件的 Internet Explorer 11 缓存的 .bat 文件时遇到一些问题:

目前我使用附加的代码,但它会删除缓存中的所有文件 (OS = Windows 10):

@echo off

set DataDir=C:\Users\%USERNAME%\AppData\Local\Microsoft\Intern~1\

del /q /s /f "%DataDir%"
rd /s /q "%DataDir%"

set History=C:\Users\%USERNAME%\AppData\Local\Microsoft\Windows\History

del /q /s /f "%History%"
rd /s /q "%History%"

set IETemp=C:\Users\%USERNAME%\AppData\Local\Microsoft\Windows\Tempor~1

del /q /s /f "%IETemp%"
rd /s /q "%IETemp%"

set Cookies=C:\Users\%USERNAME%\AppData\Roaming\Microsoft\Windows\Cookies

del /q /s /f "%Cookies%"
rd /s /q "%Cookies%"

C:\bin\regdelete.exe HKEY_CURRENT_USER "Software\Microsoft\Internet Explorer\TypedURLs"

以下批处理脚本将遍历您提供的 4 个文件夹,并在所有子目录 (dir /b /s /a:-d "%%~f") 中搜索所有三个文件(请参阅 how to loop through arrays in batch)。

如果脚本适合您,请删除 del 命令前面的 echo

@echo off

set "filesDel[0]=Analytics.swf"
set "filesDel[1]=Deal.swf"
set "filesDel[2]=Pricing.swf"

set "dirDel[0]=%LocalAppData%\Microsoft\Intern~1"
set "dirDel[1]=%LocalAppData%\Microsoft\Windows\History"
set "dirDel[2]=%LocalAppData%\Microsoft\Windows\Tempor~1"
set "dirDel[3]=%AppData%\Microsoft\Windows\Cookies"

rem loop over all directories defined in dirDel array
for /f "tokens=2 delims==" %%d in ('set dirDel[') do (
   if exist "%%~d" (
      pushd "%%~d"
      rem loop over all files defined in filedDel array
      for /f "tokens=2 delims==" %%f in ('set filesDel[') do (
         rem search for file and delete it
         for /f "tokens=*" %%g in ('dir /b /s /a:-d "%%~f"') do (
            echo del /f "%%~g"
         )
      )
      popd
   )
)

请注意,我在 set 命令中使用了引号,例如:set "name=content",这允许在路径名中使用空格,而不在变量内容本身中使用引号。


来自 ss64.com 的命令参考链接: