@echo off&setlocal enabledelayedexpansion ::不适用于智能镜像,仅适用于完全镜像,感谢双心版主提供帮助 set dd=C: ::设置要回收的盘符如C: for /f "tokens=1 delims= " %%i in ('wmic logicaldisk where "caption='%dd%'" get freespace') do ( set /a n+=1 if !n!==2 (set size=%%i) else echo >nul ) fsutil file createnew %dd%\test.zip %size% del /f /q %dd%\test.zip exit
set dd=C: ::设置要回收的盘符如C: for /f "tokens=1 delims= " %%i in ('wmic logicaldisk where "caption='%dd%'" get freespace') do ( set /a n+=1 if !n!==2 (set size=%%i) else echo >nul ) fsutil file createnew %dd%\test.zip %size% del /f /q %dd%\test.zip exit
由本论坛yiyu2012改进的更完美的批处理如下
@echo off
setlocal EnableDelayedExpansion
:: 获取管理员权限
set _Args=%*
if "%~1" NEQ "" (
set _Args=%_Args:"=%
)
fltmc 1>nul 2>nul || (
cd /d "%~dp0"
cmd /u /c echo Set UAC = CreateObject^("Shell.Application"^) : UAC.ShellExecute "cmd.exe", "/k cd ""%~dp0"" && ""%~dpnx0"" ""%_Args%""", "", "runas", 1 > "%temp%\GetAdmin.vbs"
"%temp%\GetAdmin.vbs"
del /f /q "%temp%\GetAdmin.vbs" 1>nul 2>nul
exit
)
cd /d "%~dp0"
set "str=U O P R W V C"
echo 开始释放内存盘%str%内存
for %%a in (%str%) do (
set ckd=%%a:
set dd=0
if exist !ckd! set dd=!ckd!
call :filldisk
)
echo.&echo 操作完成!
pause>nul
exit
:filldisk
if !dd!==0 exit /b
echo.&echo 正在释放内存盘!dd!内存...
del !dd!\test*.zip /f 1>nul 2>nul
for /f "tokens=3 delims=:" %%i in ('bootmode !dd!^|find /i "FreeSpace"') do set size=%%i
set /a n=!size!/1024
set /a nn=n+1
set /a m=!size!-n*1024-100
set /a l=m*1024*1024
set rt=0
fsutil file createnew !dd!\test_!nn!.zip !l! 1>nul 2>nul
:ctt
set /a rt+=1
fsutil file createnew !dd!\test_!rt!.zip 1073741824 1>nul 2>nul
if !rt! LSS !n! goto :ctt
del !dd!\test*.zip /f 1>nul 2>nul
exit /b