脚本(search和删除临时文件/文件夹)已经失败

我使用这个脚本来清理所有用户的历史logging,cookies和caching(Temporary Internet Files),并且它也应该清理临时目录,但似乎有什么问题。

2个东西混在一起我想,%temp%variables(= D:\ TEMP在我的环境中)和用户temp目录在%userprofile%

:: Works on Win XP -and- on Win 7 @echo off Set "RegKey=HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" set "regkey2=HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\shell folders" call:getspecialfolders "Cache, History, Cookies" For /f "tokens=*" %%? in ( 'Reg.exe QUERY "%RegKey%" ^|findstr /ric:"\S-1-5-21-[0-9]*-[0-9]*-[0-9]*-[0-9]*$"' ) do ( For /f "tokens=2,*" %%A in ( 'Reg.exe QUERY "%%?" /v ProfileImagePath ^|find /i "ProfileImagePath"' ) do call:Go %%B ) start ""/w "%windir%\system32\RunDll32.exe" InetCpl.cpl,ClearMyTracksByProcess 255 :end *** goto:EOF :Go call Set "Target=%*" If EXIST "%Target%" call:Clear "%Target%" exit /b 0 :Clear REM echo.&echo.%~1\%$$Cache% pushD "%~1\%$$Cache%" &&( rmdir /S /Q . popD)2>C:\test1_TEMP_IE.txt REM echo.&echo.%~1\%$$History%\History.IE5 REM pushD "%~1\%$$History%\History.IE5" &&( REM rmdir /S /Q . REM popD)2>C:\test1_History_IE.txt REM echo.&echo.%~1\%$$History% pushD "%~1\%$$History%" &&( rmdir /S /Q . popD)2>C:\test1_History.txt REM echo.&echo.%~1\%$$Cookies% pushD "%~1\%$$Cookies%" &&( rmdir /S /Q . popD)2>C:\test1_Cookies.txt ECHO.&echo.%~1\%$$temp% pushD "%~1\%$$temp%" &&( rmdir /S /Q . popD)2>C:\test1_Temp.txt exit /b 0 :getspecialfolders Set "FoldersToClear=%~1" For %%* in (%FoldersToClear%) Do ( For /f "tokens=2,*" %%A in ( 'reg.exe query "%regkey2%" /v %%* ^|find /i "%%~*"' ) do Call:sf1 "%%~B" "%%~*" ) Call:sf2 "%temp%" "temp" "%userprofile%" exit /b 0 :sf1 Call set "sf=%~1" Call set "$$%~2=%%sf:%userprofile%\=%%" exit /b 0 :sf2 Call set "sf=%~1" call Set "usr=%~dpns3" Call set "$$%~2=%%sf:%usr%\=%%" exit /b 0 

但不知怎的,我不能得到最后一个“临时部分”的function,所以它清理%temp%(D:\ Temp在我的环境中),也find%userprofile%中的所有“临时目录”。

即。 这个例子可以用于%temp%:

 PushD "%Temp%" && ( ATTRIB -S -H -R -A /D /S & ( For /f "Tokens=*" %%* in ('dir "%Temp%" /B') Do ( RD "%Temp%\%%*" /S /Q || Del /F /S /Q "%Temp%\%%*"))&PopD)2>c:\test0b_TEMP.txt 

这就是说。 适用于“用户temp”:

 ::Set Search directory to "Documents and Settings" folder (Set Target=%AllUsersProfile:~0,-10%) title,Finding the Temp subfolders in %Target%&COLOR 9E If EXIST "%Target%",( For /f "Tokens=*" %%* in ('dir "%Target%" /B') Do ( cd/D "%target%\%%*\Local Settings\Temp" && ( ATTRIB -S -H -R -A /D /S >nul & ( For /f "Tokens=*" %%* in ('dir /B') Do ( RD "%%*" /S /Q ||Del /F "%%*" )))>nul) ) 

我希望有人可以帮我解决这个问题,我认为这是在sf2和/或与%temp%部分结合在一起,不知何故,有两件事情会混淆(“用户临时”和“环境温度”) 。

这似乎是一个解决方法:

代替

 ECHO.&echo.%~1\%$$temp% pushD "%~1\%$$temp%" &&( rmdir /S /Q . popD)2>C:\test1_Temp.tx 

使用

 IF "%$$temp%"=="%$$temp:*:=%" (SET "tmppath=%~1\%$$temp%") ELSE SET "tmppath=%$$temp%" ECHO.&echo.%tmppath% pushD "%tmppath%" &&( rmdir /S /Q . popD)2>C:\test1_Temp.txt 

学分出去: Andriy M