我做了一个垃圾清理的bat,运行时发现出现了一些显示告诉我”找不到操作数“,我把回显打开,发现这是因为代码中很多行都是应该执行total=(!total!+%%~za),但是打开回显我看到的却全都是total=(!total!+),这样的代码完整说出来应该是:for /f "delims=" %%a in ('dir/b/s/a-d') do set /a total=(!total!+%%~za),代码如下:- @echo off
- setlocal enabledelayedexpansion
- set "t=%time%"
- echo 清理Temp文件夹(Windows临时文件):
- echo 用户Temp:
- cd/d %temp%
- set total=0
- for /f "delims=" %%a in ('dir/b/s/a-d') do set /a total=(!total!+%%~za)
- set to1=total
- del /f /s /q %temp%\*.*>nul
- echo 完毕
- echo 系统Temp:
- cd/d %systemroot%\temp
- set total=0
- for /f "delims=" %%a in ('dir/b/s/a-d') do set /a total=(!total!+%%~za)
- set to2=total
- del /f /s /q %systemroot%\temp\*.*>nul
- echo 完毕
- echo 清理补丁文件:
- cd/d %systemroot%\SoftwareDistribution\Download
- set total=0
- for /f "delims=" %%a in ('dir/b/s/a-d') do set /a total=(!total!+%%~za)
- set to3=total
- del /f /s /q %systemroot%\SoftwareDistribution\Download\*.*>nul
- echo 完毕
- echo 清理Windows日志:
- cd/d %systemroot%\system32\LogFiles
- set total=0
- for /f "delims=" %%a in ('dir/b/s/a-d') do set /a total=(!total!+%%~za)
- set to4=total
- del /f /s /q %systemroot%\system32\LogFiles\*.*>nul
- echo 完毕
- echo 清理预读取文件:
- cd/d %systemroot%\prefetch
- set total=0
- for /f "delims=" %%a in ('dir/b/s/a-d') do set /a total=(!total!+%%~za)
- set to5=total
- del /f /s /q %systemroot%\prefetch\*.*>nul
- echo 完毕
- echo 清理完成
- set "t1=%time%"
- if "%t1:~,2%" lss "%t:~,2%" set "add=+24"
- set /a "times=(%t1:~,2%-%t:~,2%%add%)*360000+(1%t1:~3,2%%%100-1%t:~3,2%%%100)*6000+(1%t1:~6,2%%%100-1%t:~6,2%%%100)*100+(1%t1:~-2%%%100-1%t:~-2%%%100)" ,"ss=(times/100)%%60","mm=(times/6000)%%60","hh=times/360000","ms=times%%100"
- set /a toe=to1+to2+to3+to4+to5
- echo 共计删除了:%toe%字节 文件
- echo 用时:%hh%时:%mm%分:%ss%秒.%ms%毫秒
- pause
- exit
复制代码
|