此时DO出人意料。错误255

时间:2014-04-04 00:59:11

标签: batch-file

我有一个批处理脚本,用于清除所有用户的缓存文件。

REM Set file locations for temp/history/cookies files.
SET SRC1=C:\Users
SET SRC2=AppData\Local\Microsoft\Windows\Temporary Internet Files
SET SRC3=AppData\Local\Microsoft\Windows\History
SET SRC4=AppData\Local\Temp
SET SRC5=AppData\Roaming\Microsoft\Windows\Cookies
SET SRC6=AppData\Local\Microsoft\Windows\Temporary Internet Files\Low\Content.IE5

REM begin cleaning internet files
echo cleaning temporary internet files
FOR /D %%X IN ("%SRC1%\*") DO FOR /D %%Y IN ("%%X\%SRC2%\*.*") DO RMDIR /S /Q "%%Y"

REM begin cleaning history files
echo cleaning history
FOR /D %%X IN ("%SRC1%\*") DO FOR /D %%Y IN ("%%X\%SRC3%\*.*") DO RMDIR /S /Q "%%Y"

REM begin cleaning windows temp files
echo cleaning windows temp files
FOR /D %%X IN ("%SRC1%\*") DO FOR /D %%Y IN ("%%X\%SRC4%\*.*") DO RMDIR /F /S /Q "%%Y"
FOR /D %%X IN ("%SRC1%\*") DO FOR %%Y IN ("%%X\%SRC3%\*.*") DO DEL /F /S /Q "%%Y"
FOR /D %%X IN ("%SRC1%\*") DO FOR %%Y IN ("%%X\%SRC4%\*.*") DO DEL /F /S /Q "%%Y"

REM begin cleaning Cookies folder
echo cleaning Cookies
FOR /D %%X IN ("%SRC1%\*") DO FOR %%Y IN ("%%X\%SRC5%\*.*") DO DEL /F /S /Q "%%Y"

REM del C:\temp folder
FOR /D %%X IN ("%windir%\temp\*") DO RMDIR /F /S /Q "%%X"
DEL /f /s /q "%windir%\temp"

REM Del Temp Internet Files
FOR /D %%x in ("%SRC6%\*") DO FOR %%Y DO DEL /F /S /Q "%%Y"
FOR /D %%x in ("%SRC1%\*") DO FOR %%Y IN ("%%X\%SRC6%\*.*") DO DEL /F /S /Q "%%Y"

:END

通过psexec运行时,我收到以下错误:

DO was unexpected at this time.
batch file exited on PCNAME with error code 255.

在其他Windows 7和XP计算机上,我能够运行此操作并收到错误消息,表明它已成功。

这是我第一次看到此错误,但我似乎无法缩小错误范围。
任何人都可以借第二双眼睛吗?

1 个答案:

答案 0 :(得分:1)

请参阅代码中的以下行。

...
REM Del Temp Internet Files
FOR /D %%x in ("%SRC6%\*") DO FOR %%Y DO DEL /F /S /Q "%%Y"
...

您缺少嵌套IN (...)循环的FOR部分。

因此:DO was unexpected at this time.