计算删除文件批的大小。

时间:2021-12-22 02:23:27

If I have the following command to delete some files I need a way of it displaying the total size of all the files before deleting them is this possible and how would I do this. The reason i need this is because I am making a program that can optimise your pc and this is a small section of the deleting bit. I can use any programming language that can be executed and used natively in windows and can be compiled to an exe.

如果我有以下命令来删除一些文件,我需要一种方法来显示所有文件的总大小,然后删除它们,这是可能的,我怎么做呢?我之所以需要这个,是因为我正在制作一个程序,可以优化你的电脑,这是删除部分的一小部分。我可以使用任何可以在windows中执行和使用的编程语言,并且可以编译为exe。

EDIT: It may be done with VBS but preferable batch.

编辑:可以用VBS完成,但最好是批量处理。

Here is the full delete script:

以下是完整的删除脚本:

del \*.tmp /s /f /q >> Log.txt
del \*.temp /s /f /q >> Log.txt
del \Thumbs.db /s /f /q >> Log.txt
erase /s/q/f "C:\$RECYCLE.BIN\*">nul
ipconfig /flushdns >> Log.txt
SET RW="%systemdrive%\Program Files (x86)\Steam\steamapps\common\railworks" >> Log.txt
DEL /S "%RW%\Blueprints.pak*" >> Log.txt
SET RW="%systemdrive%\Program Files (x64)\Steam\steamapps\common\railworks" >> Log.txt
DEL /S "%RW%\Blueprints.pak*" >> Log.txt
net stop dnscache >> Log.txt
ipconfig /flushdns >> Log.txt
net start dnscache >> Log.txt
set wowdir="%systemdrive%\Program Files (x86)\World of Warcraft\" >> Log.txt
set creature_file=%wowdir%"Cache\WDB\enUS\creaturecache.wdb" >> Log.txt
set npc_file=%wowdir%"Cache\WDB\enUS\npccache.wdb >> Log.txt
set launcher_file=%wowdir%"World of Warcraft Launcher.exe" >> Log.txt
set wowdir="%systemdrive%\Program Files (x64)\World of Warcraft\" >> Log.txt
set creature_file=%wowdir%"Cache\WDB\enUS\creaturecache.wdb" >> Log.txt
set npc_file=%wowdir%"Cache\WDB\enUS\npccache.wdb >> Log.txt
set launcher_file=%wowdir%"World of Warcraft Launcher.exe" >> Log.txt
del /q "%creature_file%" >> Log.txt
del /q "%npc_file%" >> Log.txt
cd “%APPDATA%\Microsoft\Web Server Extensions\Cache” >> Log.txt
del *.web /S /Q “%APPDATA%\Microsoft\Web Server Extensions\Cache” >> Log.txt
cd “%USERPROFILE%\AppData\Local\Microsoft\WebsiteCache\” >> Log.txt
rmdir /S /Q “%USERPROFILE%\AppData\Local\Microsoft\WebsiteCache\.” >> Log.txt
mkdir “%USERPROFILE%\AppData\Local\Microsoft\WebsiteCache” >> Log.txt
dir “%APPDATA%\Microsoft\Web Server Extensions\Cache” >> Log.txt
dir “%USERPROFILE%\AppData\Local\Microsoft\WebsiteCache” >> Log.txt
del /f /q %windir%\Prefetch\*.* >> Log.txt
del /f /q "%userprofile%\local settings\temp\*.*" >> Log.txt
del /f /q "%userprofile%\local settings\temporary internet files\*.*" >> Log.txt
FOR /D /R %TEMP% %%x IN (gwt*) DO RMDIR /S /Q "%%x" >> Log.txt
FOR /D /R %TEMP% %%x IN (*) DO RMDIR /S /Q "%%x" >> Log.txt
DEL "%TEMP%\*" /F /Q >> Log.txt
CD\ >> Log.txt
CD %Windir% >> Log.txt
CD SoftwareDistribution >> Log.txt        
DEL /F /S /Q Download >> Log.txt
CD /d %systemdrive%\windows\system32
taskkill /F /IM "chrome.exe">nul 2>&1 >> Log.txt
set ChromeDataDir=%systemdrive%\Users\%USERNAME%\AppData\Local\Google\Chrome\User Data\Default >> Log.txt
set ChromeCache=%ChromeDataDir%\Cache>nul  
del /q /s /f "%ChromeCache%\*.*">nul    
del /q /f "%ChromeDataDir%\*Cookies*.*">nul    
del /q /f "%ChromeDataDir%\*History*.*">nul     
set ChromeDataDir=%systemdrive%\Users\%USERNAME%\Local Settings\Application Data\Google\Chrome\User Data\Default >> Log.txt
set ChromeCache=%ChromeDataDir%\Cache>nul 
del /q /s /f "%ChromeCache%\*.*">nul   
del /q /f "%ChromeDataDir%\*Cookies*.*">nul    
del /q /f "%ChromeDataDir%\*History*.*">nul    
set ChromeDir=%systemdrive%\Users\%USERNAME%\AppData\Local\Google\Chrome\User Data >> Log.txt
del /q /s /f "%ChromeDir%" >> Log.txt
rd /s /q "%ChromeDir%" >> Log.txt
set DataDir=%systemdrive%\Users\%USERNAME%\AppData\Local\Mozilla\Firefox\Profiles >> Log.txt
del /q /s /f "%DataDir%" >> Log.txt
rd /s /q "%DataDir%" >> Log.txt
for /d %%x in (%systemdrive%\Users\%USERNAME%\AppData\Roaming\Mozilla\Firefox\Profiles\*) do del /q /s /f %%x\*sqlite >> Log.txt
set DataDir=%systemdrive%\Users\%USERNAME%\AppData\Local\Opera\Opera >> Log.txt
set DataDir2=%systemdrive%\Users\%USERNAME%\AppData\Roaming\Opera\Opera >> Log.txt
del /q /s /f "%DataDir%" >> Log.txt
rd /s /q "%DataDir%" >> Log.txt
del /q /s /f "%DataDir2%" >> Log.txt
rd /s /q "%DataDir2%" >> Log.txt
set DataDir=%systemdrive%\Users\%USERNAME%\AppData\Local\Applec~1\Safari >> Log.txt
set DataDir2=%systemdrive%\Users\%USERNAME%\AppData\Roaming\Applec~1\Safari >> Log.txt
del /q /s /f "%DataDir%\History" >> Log.txt
rd /s /q "%DataDir%\History" >> Log.txt
del /q /s /f "%DataDir%\Cache.db" >> Log.txt
del /q /s /f "%DataDir%\WebpageIcons.db" >> Log.txt
del /q /s /f "%DataDir2%" >> Log.txt
rd /s /q "%DataDir2%" >> Log.txt
set DataDir=%systemdrive%\Users\%USERNAME%\AppData\Local\Microsoft\Intern~1 >> Log.txt
del /q /s /f "%DataDir%" >> Log.txt
rd /s /q "%DataDir%" >> Log.txt
set History=%systemdrive%\Users\%USERNAME%\AppData\Local\Microsoft\Windows\History >> Log.txt
del /q /s /f "%History%" >> Log.txt
rd /s /q "%History%" >> Log.txt
set IETemp=%systemdrive%\Users\%USERNAME%\AppData\Local\Microsoft\Windows\Tempor~1 >> Log.txt
del /q /s /f "%IETemp%" >> Log.txt
rd /s /q "%IETemp%" >> Log.txt
set Cookies=%systemdrive%\Users\%USERNAME%\AppData\Roaming\Microsoft\Windows\Cookies >> Log.txt
del /q /s /f "%Cookies%" >> Log.txt
rd /s /q "%Cookies%" >> Log.txt
set FlashCookies=%systemdrive%\Users\%USERNAME%\AppData\Roaming\Macromedia\Flashp~1 >> Log.txt
del /q /s /f "%FlashCookies%" >> Log.txt
rd /s /q "%FlashCookies%" >> Log.txt
CD /d %systemdrive%\windows\system32 >> Log.txt
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 255 >> Log.txt
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 1 >> Log.txt
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 8 >> Log.txt
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 16 >> Log.txt
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 32 >> Log.txt
taskkill /F /IM "chrome.exe">nul 
set ChromeDataDir=%systemdrive%\Users\%USERNAME%\AppData\Local\Google\Chrome\User Data\Default >> Log.txt
set ChromeCache=%ChromeDataDir%\Cache>nul 
del /q /s /f "%ChromeCache%\*.*">nul    
del /q /f "%ChromeDataDir%\*History*.*">nul    
set ChromeDataDir=%systemdrive%\Users\%USERNAME%\Local Settings\Application Data\Google\Chrome\User Data\Default >> Log.txt
set ChromeCache=%ChromeDataDir%\Cache>nul
del /q /s /f "%ChromeCache%\*.*">nul   
del /q /f "%ChromeDataDir%\*History*.*">nul 
CD /d %systemdrive%\windows\system32 >> Log.txt
taskkill /F /IM "chrome.exe">nul 
set ChromeDataDir=%systemdrive%\Users\%USERNAME%\AppData\Local\Google\Chrome\User Data\Default >> Log.txt
set ChromeCache=%ChromeDataDir%\Cache>nul 
del /q /s /f "%ChromeCache%\*.*">nul 
del /q /f "%ChromeDataDir%\*History*.*">nul    
set ChromeDataDir=%systemdrive%\Users\%USERNAME%\Local Settings\Application Data\Google\Chrome\User Data\Default >> Log.txt
set ChromeCache=%ChromeDataDir%\Cache>nul 
del /q /s /f "%ChromeCache%\*.*">nul   
del /q /f "%ChromeDataDir%\*History*.*">nul 
CD /d %systemdrive%\windows\system32 >> Log.txt
taskkill /F /IM "chrome.exe">nul 
set ChromeDataDir=%systemdrive%\Users\%USERNAME%\AppData\Local\Google\Chrome\User Data\Default >> Log.txt
set ChromeCache=%ChromeDataDir%\Cache>nul   
del /q /s /f "%ChromeCache%\*.*">nul    
del /q /f "%ChromeDataDir%\*History*.*">nul 
set ChromeDataDir=%systemdrive%\Users\%USERNAME%\Local Settings\Application Data\Google\Chrome\User Data\Default >> Log.txt
set ChromeCache=%ChromeDataDir%\Cache>nul 
del /s /f /q "%userprofile%\AppData\Local\Apple Computer\Safari\Cache.db" >> Log.txt
del /s /f /q "%userprofile%\AppData\Local\Apple Computer\Safari\Webpage Previews" >> Log.txt
del /s /f /q "%userprofile%\AppData\Local\Apple Computer\Safari\LocalStorage" >> Log.txt
del /s /f /q "%appdata%\Microsoft\Windows\Recent" >> Log.txt
del /s /f /q "%userprofile%\AppData\Local\Google\CrashReports" >> Log.txt
del /s /f /q "%userprofile%\AppData\Local\Microsoft\Media Player\Art Cache\LocalMLS" >> Log.txt
del /s /f /q "%userprofile%\AppData\Local\Microsoft\Media Player\lastplayed.wpl" >> Log.txt
del /s /f /q "%appdata%\Microsoft\Office\Recent" >> Log.txt
del /s /f /q "%userprofile%\AppData\Local\IconCache.db" >> Log.txt
del /s /f /q "%userprofile%\AppData\Local\GDIPFONTCACHEV1.DAT" >> Log.txt
del /s /f /q "%userprofile%\AppData\Local\Opera\Opera" >> Log.txt
del /s /f /q "%userprofile%\AppData\Local\Microsoft Corporation\Windows 7 Upgrade Advisor" >> Log.txt
del /s /f /q "%userprofile%\AppData\Local\Microsoft\Windows Mail\Backup" >> Log.txt
del /s /f /q "%userprofile%\AppData\Local\Microsoft\Windows\Explorer\thumbcache_32.db" >> Log.txt
del /s /f /q "%userprofile%\AppData\Local\Microsoft\Windows\Explorer\thumbcache_96.db" >> Log.txt
del /s /f /q "%userprofile%\AppData\Local\Microsoft\Windows\Explorer\thumbcache_256.db" >> Log.txt
del /s /f /q "%userprofile%\AppData\Local\Microsoft\Windows\Explorer\thumbcache_1024.db" >> Log.txt
del /s /f /q "%userprofile%\AppData\Local\Microsoft\Windows\Explorer\thumbcache_idx.db" >> Log.txt
del /s /f /q "%userprofile%\AppData\Local\Microsoft\Windows\Explorer\thumbcache_sr.db" >> Log.txt
del /s /f /q "%userprofile%\AppData\Local\Microsoft\Windows\Caches" >> Log.txt
del /s /f /q "%userprofile%\AppData\Local\Microsoft\Windows\Burn\Burn" >> Log.txt
del /s /f /q "%userprofile%\AppData\Local\Microsoft\Media Player\Transcoded Files Cache" >> Log.txt
del /s /f /q "%userprofile%\AppData\Local\Microsoft\Device Metadata\dmrccache\downloads" >> Log.txt
del /s /f /q "%userprofile%\AppData\Local\Diagnostics" >> Log.txt
del /s /f /q "%userprofile%\AppData\Local\CometNetwork\CometBird\Profiles\u4k8vhhn.default\startupCache" >> Log.txt
del /s /f /q "%userprofile%\AppData\Local\CometNetwork\CometBird\Profiles\u4k8vhhn.default\Cache" >> Log.txt
del /s /f /q "%windir%\setuplog.txt" >> Log.txt
del /s /f /q "%userprofile%\AppData\Roaming\FixCleaner\Logs\" >> Log.txt
del /s /f /q "%windir%\logs\" >> Log.txt
del /s /f /q "%windir%\SoftwareDistribution\DataStore\Logs\" >> Log.txt
del /s /f /q "%Programdata%\AVAST Software\Persistent Data\Avast\Logs\" >> Log.txt
del /s /f /q "%appdata%\.minecraft\crash-reports\" >> Log.txt
del /s /f /q "%userprofile%\AppData\Local\Microsoft\Windows\WindowsUpdate.log" >> Log.txt
del /s /f /q "%windir%\winsxs\x86_microsoft-windows-com-dtc-runtime_31bf3856ad364e35_6.1.7600.16385_none_19295908c15690f3\MSDTC.LOG" >> Log.txt
del /s /f /q "%windir%\System32\SMI\Store\Machine\SCHEMA.DAT.LOG2" >> Log.txt
del /s /f /q "%windir%\system32\LocalGroupAdminAdd.log" >> Log.txt
del /s /f /q "%windir%\system32\Network_LLU.log" >> Log.txt
del /s /f /q "%windir%\system32\Local_LLU.log" >> Log.txt
del /s /f /q "%windir%\system32\InstallPackage_ETW.Log" >> Log.txt
del /s /f /q "%windir%\inf\setupapi.offline.log" >> Log.txt
del /s /f /q "%windir%\Panther\UnattendGCsetuperr.log" >> Log.txt
del /s /f /q "%windir%\System32\sysprep\Panther\IE\setuperr.log" >> Log.txt
del /s /f /q "%windir%\System32\sysprep\Panther\IE\setupact.log" >> Log.txt
del /s /f /q "%windir%\Panther\DDACLSys.log" >> Log.txt
del /s /f /q "%windir%\Panther\setupact.log" >> Log.txt
del /s /f /q "%windir%\Panther\UnattendGC\setupact.log" >> Log.txt
del /s /f /q "%windir%\Microsoft.NET\Framework\v2.0.50727\ngen_service.log" >> Log.txt
del /s /f /q "%windir%\Microsoft.NET\Framework\v2.0.50727\ngen.log" >> Log.txt
del /s /f /q "%windir%\Panther\setuperr.log" >> Log.txt
del /s /f /q "%windir%\Panther\cbs.log" >> Log.txt
del /s /f /q "%windir%\System32\MRT\21063288-61F8-4060-9629-9DBDD77E3242\MpGearSupport_20131019_113721117.log" >> Log.txt
del /s /f /q "%windir%\System32\MRT\21063288-61F8-4060-9629-9DBDD77E3242\MpGearSupport_20131019_115612188.log" >> Log.txt
del /s /f /q "%windir%\System32\Macromed\Flash\install.log" >> Log.txt
del /s /f /q "%windir%\setuperr.log" >> Log.txt
del /s /f /q "%windir%\debug\WIA\wiatrace.log" >> Log.txt
del /s /f /q "%windir%\Performance\WinSAT\winsat.log" >> Log.txt
del /s /f /q "%windir%\SoftwareDistribution\DataStore\Logs\FlashInstall.log" >> Log.txt
del /s /f /q "%windir%\debug\mrt.log" >> Log.txt
del /s /f /q "%windir%\System32\MRT\BA6D0F21-C17B-418A-8ADD-B18289A02461\MpGearSupport_20131208_101543044.log" >> Log.txt
del /s /f /q "%windir%\IE9_main.log" >> Log.txt
del /s /f /q "%windir%\DPINST.LOG" >> Log.txt
del /s /f /q "%windir%\msxml4-KB973688-enu.LOG" >> Log.txt
del /s /f /q "%windir%\Microsoft.NET\Framework\v4.0.30319\HPSLPSVC0007.log" >> Log.txt
del /s /f /q "%windir%\Microsoft.NET\Framework\v4.0.30319\ngen_service.log" >> Log.txt
del /s /f /q "%windir%\IE10_main.log" >> Log.txt
del /s /f /q "%windir%\PFRO.log" >> Log.txt
del /s /f /q "%windir%\SoftwareDistribution\DataStore\Logs\" >> Log.txt
del /s /f /q "%windir%\inf\setupapi.dev.log" >> Log.txt
del /s /f /q "%windir%\SoftwareDistribution\ReportingEvents.log" >> Log.txt
del /s /f /q "%windir%\Logs\CBS\CBS.log" >> Log.txt
del /s /f /q "%windir%\setupact.log" >> Log.txt
del /s /f /q "%windir%\inf\setupapi.app.log" >> Log.txt
del /s /f /q "%windir%\WindowsUpdate.log" >> Log.txt
del /s /f /q "%windir%\SoftwareDistribution\DataStore\Logs\edb.log" >> Log.txt
del /s /f /q %appdata%\.minecraft\crash-reports\*.* /s >> Log.txt
del /s /f /q %Programdata%\AVAST Software\Persistent Data\Avast\Logs\*.* /s >> Log.txt
del /s /f /q %windir%\SoftwareDistribution\DataStore\Logs\*.* /s >> Log.txt
del /s /f /q %windir%\logs\*.* /s >> Log.txt
del /s /f /q %windir%\temp\*.* /s >> Log.txt
del /s /f /q %userprofile%\Local Settings\temp\*.* /s >> Log.txt
del /s /f /q %userprofile%\AppData\Roaming\FixCleaner\Logs\*.* /s >> Log.txt
erase /s/q/f "%systemdrive%\temp" >> Log.txt
erase /s/q/f "%systemdrive%\documents and settings\administrator\recent" >> Log.txt
erase /s/q/f "%systemdrive%\documents and settings\administrator\my recent documents" >> Log.txt
erase /s/q/f "%systemdrive%\documents and settings\administrator\local settings\my recent documents" >> Log.txt
rmdir /s/q "%systemdrive%\quarantine" >> Log.txt
erase /s/q/f "%windir%\downloaded program files" >> Log.txt
erase /s/q/f "%windir%\recent" >> Log.txt
erase /s/q/f "%windir%\applog" >> Log.txt
erase /s/q/f "%windir%\desktop\*.tmp" >> Log.txt
erase /s/q/f "%systemdrive%\documents and settings\administrator\cookies" >> Log.txt
erase /s/q/f "%systemdrive%\documents and settings\administrator\local settings\history" >> Log.txt
erase /s/q/f "%systemdrive%\documents and settings\administrator\local settings\temp" >> Log.txt
erase /s/q/f "%systemdrive%\documents and settings\administrator\local settings\temporary internet files" >> Log.txt
erase /s/q/f "%systemdrive%\documents and settings\administrator\local settings\application data" >> Log.txt
erase /s/q/f "%systemdrive%\documents and settings\administrator\userdata" >> Log.txt
erase /s/q/f "%systemdrive%\documents and settings\administrator\my recent documents" >> Log.txt
erase /s/q/f "%windir%\system32\catroot2\*.log" >> Log.txt
erase /s/q/f "%systemdrive%\documents and Settings\administrator\application data\mozilla\Profiles\default\mhy0feee.slt\cache" >> Log.txt
erase /s/q/f "%systemdrive%\documents and Settings\administrator\application data\mozilla\Profiles\default\mhy0feee.slt\cache.Trash" >> Log.txt
erase /s/q/f "%systemdrive%\documents and Settings\administrator\application data\mozilla\Profiles\default\mhy0feee.slt\cookies.txt" >> Log.txt
erase /s/q/f "%systemdrive%\documents and settings\administrator\application data\mozilla\Profiles\default\mhy0feee.slt\downloads.rdf" >> Log.txt
erase /s/q/f "%systemdrive%\documents and settings\administrator\application data\mozilla\Profiles\default\mhy0feee.slt\history.dat" >> Log.txt
erase /s/q/f "%systemdrive%\documents and settings\administrator\application data\mozilla\Profiles\default\mhy0feee.slt\bookmarks.html" >> Log.txt
erase /s/q/f "%windir%\debug\usermode\userenv.log" >> Log.txt
erase /s/q/f "%windir%\debug\usermode\userenv.bak" >> Log.txt
netsh int tcp show global >> Log.txt
netsh int tcp set global chimney=enabled" Without >> Log.txt
netsh int tcp set global autotuninglevel=normal >> Log.txt
netsh int tcp set global congestionprovider=ctcp >> Log.txt
regsvr32 actxprxy.dll >> Log.txt
REG add "HKCU\Control Panel\Desktop" /v ForegroundLockTimeout /t REG_DWORD /d 0 /f >> Log.txt
REG add "HKCU\Control Panel\Desktop" /v MenuShowDelay /t REG_SZ /d 100 /f >> Log.txt
REG add "HKLM\SYSTEM\CurrentControlSet\Control" /v WaitToKillServiceTimeout /t REG_SZ /d 5000 /f >> Log.txt
DEL "%systemdrive%\Users\Public\Games\World of Warcraft\Cache\WDB\enUS\creaturecache.wdb" >> Log.txt
del \*.tmp /s /f /q >> Log.txt
del \*.temp /s /f /q >> Log.txt
del \Thumbs.db /s /f /q >> Log.txt
del %windir%\system32\spool\printers\*.shd >> Log.txt
del %windir%\system32\spool\printers\*.spl >> Log.txt
CD\ >> Log.txt
CD %Windir% >> Log.txt
CD SoftwareDistribution >> Log.txt
DEL /F /S /Q Download >> Log.txt
cd %homepath%\Local Settings\Application Data\Google\Chrome\User Data\Default >> Log.txt
del "histor~1" >> Log.txt
del "histor~2" >> Log.txt
del "histor~3" >> Log.txt
del "histor~4" >> Log.txt
del "history" >> Log.txt
del "archiv~1" >> Log.txt
del "archiv~2" >> Log.txt
del "topsit~1" >> Log.txt
del "topsit~2" >> Log.txt
del "lastse~1" >> Log.txt
del "lastta~1" >> Log.txt
del "curren~1" >> Log.txt
del "curren~2" >> Log.txt
del "visite~1" >> Log.txt
del /y "cache" >> Log.txt
net stop spooler >> Log.txt
del "%systemdrive%\system32\spool\printers\*.shd" >> Log.txt
del "%systemdrive%\system32\spool\printers\*.spl" >> Log.txt
net start spooler >> Log.txt
SET x=del /s /q %systemdrive%\Users\%username%\AppData\Local\Microsoft\Windows\History\low\* /ah >> Log.txt
SET x=RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 1 >> Log.txt
SET x=RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 2 >> Log.txt
SET x=RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 8 >> Log.txt
SET x=RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 16 >> Log.txt
SET x=RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 32 >> Log.txt
SET x=RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 255 >> Log.txt
SET x=RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 4351 >> Log.txt
del "%systemdrive%\Documents and Settings\My Computer\My Documents\Electronic Arts\The Sims 3\CASPartCache.package" >> Log.txt
del "%systemdrive%\Documents and Settings\My Computer\My Documents\Electronic Arts\The Sims 3\scriptCache.package" >> Log.txt
del "%systemdrive%\Documents and Settings\My Computer\My Documents\Electronic Arts\The Sims 3\compositorCache.package" >> Log.txt
del "%systemdrive%\Documents and Settings\My Computer\My Documents\Electronic Arts\The Sims 3\simCompositorCache.package" >> Log.txt
del %systemdrive%\Thumbs.db / f / s / q / a >> Log.txt
del /q "%systemdrive%\winnt\temp\*.*" >> Log.txt
del /q "%systemdrive%\temp\*.*" >> Log.txt
del /q "%systemdrive%\winnt\Recent\*.*" >> Log.txt
del /q "%systemdrive%\*.chk" >> Log.txt

These are the file's I will add folders later:

这些是文件之后我会添加文件夹:

del \*.tmp /s /f /q >> Log.txt
del \*.temp /s /f /q >> Log.txt
del \Thumbs.db /s /f /q >> Log.txt
SET RW="%systemdrive%\Program Files (x86)\Steam\steamapps\common\railworks" >> Log.txt
DEL /S "%RW%\Blueprints.pak*" >> Log.txt
SET RW="%systemdrive%\Program Files (x64)\Steam\steamapps\common\railworks" >> Log.txt
DEL /S "%RW%\Blueprints.pak*" >> Log.txt
set wowdir="%systemdrive%\Program Files (x86)\World of Warcraft\" >> Log.txt
set creature_file=%wowdir%"Cache\WDB\enUS\creaturecache.wdb" >> Log.txt
set npc_file=%wowdir%"Cache\WDB\enUS\npccache.wdb >> Log.txt
set launcher_file=%wowdir%"World of Warcraft Launcher.exe" >> Log.txt
set wowdir="%systemdrive%\Program Files (x64)\World of Warcraft\" >> Log.txt
set creature_file=%wowdir%"Cache\WDB\enUS\creaturecache.wdb" >> Log.txt
set npc_file=%wowdir%"Cache\WDB\enUS\npccache.wdb >> Log.txt
set launcher_file=%wowdir%"World of Warcraft Launcher.exe" >> Log.txt
del /q "%creature_file%" >> Log.txt
del /q "%npc_file%" >> Log.txtset DataDir=%systemdrive%\Users\%USERNAME%\AppData\Local\Applec~1\Safari >> Log.txt
set DataDir2=%systemdrive%\Users\%USERNAME%\AppData\Roaming\Applec~1\Safari >> Log.txt
del /q /s /f "%DataDir%\Cache.db" >> Log.txt
del /q /s /f "%DataDir%\WebpageIcons.db" >> Log.txt
del /s /f /q "%userprofile%\AppData\Local\Apple Computer\Safari\Cache.db" >> Log.txt
del /s /f /q "%userprofile%\AppData\Local\Apple Computer\Safari\Webpage Previews" >> Log.txt
del /s /f /q "%userprofile%\AppData\Local\Microsoft\Media Player\lastplayed.wpl" >> Log.txt
del /s /f /q "%userprofile%\AppData\Local\IconCache.db" >> Log.txt
del /s /f /q "%userprofile%\AppData\Local\GDIPFONTCACHEV1.DAT" >> Log.txt
del /s /f /q "%userprofile%\AppData\Local\Microsoft\Windows\Explorer\thumbcache_32.db" >> Log.txt
del /s /f /q "%userprofile%\AppData\Local\Microsoft\Windows\Explorer\thumbcache_96.db" >> Log.txt
del /s /f /q "%userprofile%\AppData\Local\Microsoft\Windows\Explorer\thumbcache_256.db" >> Log.txt
del /s /f /q "%userprofile%\AppData\Local\Microsoft\Windows\Explorer\thumbcache_1024.db" >> Log.txt
del /s /f /q "%userprofile%\AppData\Local\Microsoft\Windows\Explorer\thumbcache_idx.db" >> Log.txt
del /s /f /q "%userprofile%\AppData\Local\Microsoft\Windows\Explorer\thumbcache_sr.db" >> Log.txt
del /s /f /q "%windir%\setuplog.txt" >> Log.txt
del /s /f /q "%userprofile%\AppData\Local\Microsoft\Windows\WindowsUpdate.log" >> Log.txt
del /s /f /q "%windir%\winsxs\x86_microsoft-windows-com-dtc-runtime_31bf3856ad364e35_6.1.7600.16385_none_19295908c15690f3\MSDTC.LOG" >> Log.txt
del /s /f /q "%windir%\System32\SMI\Store\Machine\SCHEMA.DAT.LOG2" >> Log.txt
del /s /f /q "%windir%\system32\LocalGroupAdminAdd.log" >> Log.txt
del /s /f /q "%windir%\system32\Network_LLU.log" >> Log.txt
del /s /f /q "%windir%\system32\Local_LLU.log" >> Log.txt
del /s /f /q "%windir%\system32\InstallPackage_ETW.Log" >> Log.txt
del /s /f /q "%windir%\inf\setupapi.offline.log" >> Log.txt
del /s /f /q "%windir%\Panther\UnattendGCsetuperr.log" >> Log.txt
del /s /f /q "%windir%\System32\sysprep\Panther\IE\setuperr.log" >> Log.txt
del /s /f /q "%windir%\System32\sysprep\Panther\IE\setupact.log" >> Log.txt
del /s /f /q "%windir%\Panther\DDACLSys.log" >> Log.txt
del /s /f /q "%windir%\Panther\setupact.log" >> Log.txt
del /s /f /q "%windir%\Panther\UnattendGC\setupact.log" >> Log.txt
del /s /f /q "%windir%\Microsoft.NET\Framework\v2.0.50727\ngen_service.log" >> Log.txt
del /s /f /q "%windir%\Microsoft.NET\Framework\v2.0.50727\ngen.log" >> Log.txt
del /s /f /q "%windir%\Panther\setuperr.log" >> Log.txt
del /s /f /q "%windir%\Panther\cbs.log" >> Log.txt
del /s /f /q "%windir%\System32\MRT\21063288-61F8-4060-9629-9DBDD77E3242\MpGearSupport_20131019_113721117.log" >> Log.txt
del /s /f /q "%windir%\System32\MRT\21063288-61F8-4060-9629-9DBDD77E3242\MpGearSupport_20131019_115612188.log" >> Log.txt
del /s /f /q "%windir%\System32\Macromed\Flash\install.log" >> Log.txt
del /s /f /q "%windir%\setuperr.log" >> Log.txt
del /s /f /q "%windir%\debug\WIA\wiatrace.log" >> Log.txt
del /s /f /q "%windir%\Performance\WinSAT\winsat.log" >> Log.txt
del /s /f /q "%windir%\SoftwareDistribution\DataStore\Logs\FlashInstall.log" >> Log.txt
del /s /f /q "%windir%\debug\mrt.log" >> Log.txt
del /s /f /q "%windir%\System32\MRT\BA6D0F21-C17B-418A-8ADD-B18289A02461\MpGearSupport_20131208_101543044.log" >> Log.txt
del /s /f /q "%windir%\IE9_main.log" >> Log.txt
del /s /f /q "%windir%\DPINST.LOG" >> Log.txt
del /s /f /q "%windir%\msxml4-KB973688-enu.LOG" >> Log.txt
del /s /f /q "%windir%\Microsoft.NET\Framework\v4.0.30319\HPSLPSVC0007.log" >> Log.txt
del /s /f /q "%windir%\Microsoft.NET\Framework\v4.0.30319\ngen_service.log" >> Log.txt
del /s /f /q "%windir%\IE10_main.log" >> Log.txt
del /s /f /q "%windir%\PFRO.log" >> Log.txt
del /s /f /q "%windir%\SoftwareDistribution\DataStore\Logs\" >> Log.txt
del /s /f /q "%windir%\inf\setupapi.dev.log" >> Log.txt
del /s /f /q "%windir%\SoftwareDistribution\ReportingEvents.log" >> Log.txt
del /s /f /q "%windir%\Logs\CBS\CBS.log" >> Log.txt
del /s /f /q "%windir%\setupact.log" >> Log.txt
del /s /f /q "%windir%\inf\setupapi.app.log" >> Log.txt
del /s /f /q "%windir%\WindowsUpdate.log" >> Log.txt
del /s /f /q "%windir%\SoftwareDistribution\DataStore\Logs\edb.log" >> Log.txt
erase /s/q/f "%windir%\system32\catroot2\*.log" >> Log.txt
erase /s/q/f "%systemdrive%\documents and Settings\administrator\application data\mozilla\Profiles\default\mhy0feee.slt\cache" >> Log.txt
erase /s/q/f "%systemdrive%\documents and Settings\administrator\application data\mozilla\Profiles\default\mhy0feee.slt\cache.Trash" >> Log.txt
erase /s/q/f "%systemdrive%\documents and Settings\administrator\application data\mozilla\Profiles\default\mhy0feee.slt\cookies.txt" >> Log.txt
erase /s/q/f "%systemdrive%\documents and settings\administrator\application data\mozilla\Profiles\default\mhy0feee.slt\downloads.rdf" >> Log.txt
erase /s/q/f "%systemdrive%\documents and settings\administrator\application data\mozilla\Profiles\default\mhy0feee.slt\history.dat" >> Log.txt
erase /s/q/f "%systemdrive%\documents and settings\administrator\application data\mozilla\Profiles\default\mhy0feee.slt\bookmarks.html" >> Log.txt
erase /s/q/f "%windir%\debug\usermode\userenv.log" >> Log.txt
erase /s/q/f "%windir%\debug\usermode\userenv.bak" >> Log.txt
DEL "%systemdrive%\Users\Public\Games\World of Warcraft\Cache\WDB\enUS\creaturecache.wdb" >> Log.txt
del "%systemdrive%\Documents and Settings\My Computer\My Documents\Electronic Arts\The Sims 3\CASPartCache.package" >> Log.txt
del "%systemdrive%\Documents and Settings\My Computer\My Documents\Electronic Arts\The Sims 3\scriptCache.package" >> Log.txt
del "%systemdrive%\Documents and Settings\My Computer\My Documents\Electronic Arts\The Sims 3\compositorCache.package" >> Log.txt
del "%systemdrive%\Documents and Settings\My Computer\My Documents\Electronic Arts\The Sims 3\simCompositorCache.package" >> Log.txt
del %systemdrive%\Thumbs.db / f / s / q / a >> Log.txt

3 个解决方案

#1


2  

You can try something like this. As it, it will not handle cluster size, as to speed operations output of dir command is used to get the file size for each branch to avoid as much partial sums as possible. Then, size occupied by the folders itself is added to the size of the files.

你可以试试这个。由于它不会处理集群大小,所以使用dir命令的速度操作输出来获取每个分支的文件大小,以避免尽可能多的部分和。然后,将文件夹本身占用的大小添加到文件的大小。

To avoid the problem with batch arithmetic limit of 2^31 max value, a simple pen and paper sum is done. It should handle up to exabytes, but if more is needed, it is configurable.

避免与批处理算法的极限问题2 ^ 31最大价值,做一个简单的纸和笔数目。它应该处理exabytes,但是如果需要更多,它是可配置的。

@echo off
    setlocal enableextensions disabledelayedexpansion

    call :initAddSize

    call :AddSize "%temp%" "*" /s
    call :AddSize "%userprofile%\AppData\Local\Microsoft\Windows\Explorer" "thumbcache_*.db" 
    call :AddSize "c:\thisdoesnotexist" "*" /s

    call :GetTotalSize finalSize

    echo(
    echo(Total space occupied on disk: [%finalSize% bytes]
    echo(

    endlocal
    exit /b



:: AddSize
::     Recursive add file and folder sizes 

:AddSize folder [fileMask] [recurse]

    :: check if internal variables has been defined and prepare environment
    if not defined _add.total call :initAddSize
    setlocal enabledelayedexpansion

    :: Retrieve and adjust parameters
    set "folder=%~1"
    if not defined folder set "folder=%cd%"
    set "recurse="
    if /i "%~3"=="/s" (
       set "recurse=/s"
    )
    set "fileMask="
    if /i "%~2"=="/s" (
        set "recurse=/s"
    ) else (
        set "fileMask=%~2"
    )
    if not defined fileMask set "fileMask=*"

    :: If folder does not exist, nothing to do
    if not exist "%folder%\" ( endlocal & goto :eof )

    :: Size files on disk is retrieved from summary in dir command output
    :: Lines starting with at least two spaces belong to the summary

    if defined debug echo Searching files... [%folder%\%fileMask%]

    set "tempSize=0"
    for /f "tokens=3,5" %%y in (
        'dir /-c /a /w %recurse% "%folder%\%fileMask%" 2^>nul ^| findstr /b /c:"  "'
    ) do if "%%~z"=="" set "tempSize=%%~y"

    :: If files has been found, add its size 
    if not "%tempSize%"=="0" call :doAddSize %tempSize%

    :: Get the size on disk of the folders. 
    :: If recursive search is selected the sum is handled in a variable, 
    :: with periodic chekcs to avoid possible overflow in batch arithmetics.
    :: If not recursive search is selected, size of the folder is only
    :: added if all its content is selected (fileMask=*)

    if defined debug echo Sizing folders...  [%folder%]

    set "_fsz=0"
    if defined recurse (
        for /d /r "%folder%" %%z in (.) do (
            set /a "_fsz+=%%~zz"
            if !_fsz! gtr 1073741824 (
                call :doAddSize !_fsz!
                set "_fsz=0"
            )
        )
        if !_fsz! gtr 0 call :doAddSize %_fsz%
    ) else (
        if "%fileMask%"=="*" for /d %%z in ("%folder%") do call :doAddSize %%~zz
    )

    :: Calc operations done for the current folder. 
    :: Cleanup and exit

    endlocal & set "_add.total=%_add.total%"
    goto :eof


:: GetTotalSize
::     Returns the content of the internal variable used to acumulate the 
::     sucessive operations. To simplify cacls, it is stored in reverse 
::     order, so, we need to reverse it to output

:GetTotalSize [variable]
    setlocal enabledelayedexpansion
    set "_output="
    for /l %%z in (0 1 %_add.precision%) do set "_output=!_add.total:~%%z,1!!_output!"
    endlocal & if not "%~1"=="" ( set "%~1=%_output%" ) else echo(%_output%
    goto :eof


:: initAddSize
::     Initialize the internal variables used to handle output to console 
::     and to acumulate the sucessive sizes.

:initAddSize
    :: Initialize variables needed for calcs. By default "only" 20 digits will be handled
    :: in operations (10 EB) . If more or less are needed, change variable
    set "_add.total=0"
    set "_add.precision=20"
    goto :eof


:: doAddSize
::    Internal function to handle the adition of values without the problems
::    of arithmetic overflow in batch files.
::    This is nothing more than a pen and paper sum.

:doAddSize size
    setlocal enabledelayedexpansion
    set "_sz=%~1"
    set "_t=%_add.total%"
    set "_s=0"
    set "_c=0"
    set "_o="
    for /l %%z in (0 1 %_add.precision%) do (
        if defined _sz (
            set /a "_s=!_t:~%%z,1!+!_sz:~-1!+!_c!+0"
            set "_sz=!_sz:~0,-1!"
            set /a "_c=!_s!/10"
            set "_o=!_o!!_s:~-1!"
        ) else if !_c! gtr 0 (
            set /a "_s=!_t:~%%z,1!+!_c!+0"
            set /a "_c=!_s!/10"
            set "_o=!_o!!_s:~-1!"
        ) else if not "!_t:~%%z,1!"=="" set "_o=!_o!!_t:~%%z,1!"
    )
    endlocal & set "_add.total=%_o%"
    goto :eof

#2


3  

The solution to this problem is comprised of two parts.

这个问题的解决方案由两部分组成。

The minimum disk space that a file occupy on disk is a cluster, that is, all files have assigned a whole number of clusters on disk. For example, if the cluster size is 4 KB, then files from 1 to 4096 bytes occupy one cluster (4 KB), files from 4097 to 8192 bytes occupy 2 clusters (8 KB), etc. When a file is deleted, the number of clusters it occupy is released from disk, so the space recovered is generally larger than the file size; clusters always have sizes in multiples of KB. This way, in order to know the space that is recovered when files are deleted, we must know first the size of the cluster on the disk.

文件占用磁盘上的最小磁盘空间是一个集群,即所有文件都在磁盘上分配了大量集群。例如,如果集群大小为4 KB,那么文件从1到4096字节占用一个集群(4 KB),从4097年到8192字节占用2集群文件(8 KB),等。当一个文件被删除,它占领的群集的数量从磁盘被释放,所以空间恢复通常大于文件大小;集群的大小通常是KB的倍数。这样,为了了解在删除文件时恢复的空间,我们必须首先知道磁盘上集群的大小。

Although we may get the cluster size from chkdsk or fsutil commands, they have some problems in its use (like require credentials to execute them), so we will use an indirect method to get the cluster size instead: get the free space on disk, delete a small file (with size less than one cluster), and get the new free space; the difference between the two sizes is the cluster size. Please, note that very small files are stored in Windows NTFS disks using a different method, so the creation or deletion of very small files does not affect the total free space in the disk.

虽然我们可能得到chkdsk集群大小或fsutil命令,他们有其使用中存在的问题(如需要凭证执行),所以我们将使用一种间接方法来获取集群大小相反:磁盘上的*空间,删除一个小文件(大小不超过一个集群),并获得新的*空间;两种大小的区别是集群大小。请注意,非常小的文件使用不同的方法存储在Windows NTFS磁盘中,因此创建或删除非常小的文件并不会影响磁盘上的全部空闲空间。

Once you have the cluster size just get the size of each file and convert it to a number of clusters using this formula: set /A clusters=(fileSize-1)/clusterSize+1. If the cluster size is 4096 bytes, previous formula gives 1 cluster for sizes 1..4096, gives 2 clusters for sizes 4097..8192, etc. At end, multiply the total number of clusters by the size of the cluster in KB and you get the total space occupied by the files on disk, that is, the space that will be recovered when such files be deleted.

一旦您拥有了集群大小,只需获取每个文件的大小,并使用这个公式将其转换成多个集群:set / a集群=(fileSize-1)/clusterSize+1。如果集群大小为4096字节,则先前的公式将为1提供一个集群。4096,提供2个大小为4097的集群。最后,将集群的总数量乘以KB的集群大小,然后得到磁盘上文件占用的总空间,即删除这些文件时将恢复的空间。

The Batch file below is an example of previous description:

下面的批处理文件是之前描述的一个示例:

@echo off
setlocal EnableDelayedExpansion

REM FIRST PART: Get the cluster size

rem Create a file with 1000 bytes
set "line=X"
for /L %%i in (1,1,997) do set "line=!line!X"
echo %line%> temp.XYZ

rem Get free disk space with this file
for /F "tokens=3" %%a in ('dir /-C temp.XYZ') do set orig=%%a

rem Delete this file and get the new disk free space
copy nul temp.XYZ /y > NUL
for /F "tokens=3" %%a in ('dir /-C temp.XYZ') do set new=%%a
del temp.XYZ

echo New space after deleted 1000 bytes: %new%
echo Original free space:                %orig%

rem Get the cluster size
:cutFirstDigit
   set "new=%new:~1%"
   set "orig=%orig:~1%"
if "%new:~0,1%" equ "%orig:~0,1%" goto cutFirstDigit
set /A clusterSize=new-orig, clusterSizeKB=clusterSize/1024
echo/
echo Cluster size: %clusterSize% bytes (%clusterSizeKB% KB)
echo/
echo/

REM SECOND PART: Get the space occupied by several files selected by first parameter

set totalClusters=0
for %%a in (%1) do (
   set /A "totalClusters+=(%%~Za-1)/clusterSize+1"
)
set /A totalSizeKB=totalClusters*clusterSizeKB, totalSizeMB=totalSizeKB/1024, totalSizeGB=totalSizeMB/1024
echo Total size occupied by %1 files: %totalSizeKB% KB  (%totalSizeMB% MB)  (%totalSizeGB% GB)

EDIT: Reply to the comments

编辑:回复评论。

Previous code show how to "calculate the size of deleted files" given in the first parameter. Of course, you have to insert the list of the desired files instead %1 in order to calculate the total size of any files you want. For example:

前面的代码演示了如何“计算第一个参数中删除文件的大小”。当然,您必须插入所需文件的列表,而不是%1,以便计算所需文件的总大小。例如:

@echo off
setlocal EnableDelayedExpansion

REM FIRST PART: Get the cluster size

rem Create a file with 1000 bytes
set "line=X"
for /L %%i in (1,1,997) do set "line=!line!X"
echo %line%> temp.XYZ

rem Get free disk space with this file
for /F "tokens=3" %%a in ('dir /-C temp.XYZ') do set orig=%%a

rem Delete this file and get the new disk free space
copy nul temp.XYZ /y > NUL
for /F "tokens=3" %%a in ('dir /-C temp.XYZ') do set new=%%a
del temp.XYZ

rem Get the cluster size
:cutFirstDigit
   set "new=%new:~1%"
   set "orig=%orig:~1%"
if "%new:~0,1%" equ "%orig:~0,1%" goto cutFirstDigit
set /A clusterSize=new-orig, clusterSizeKB=clusterSize/1024

REM SECOND PART: Get the space occupied by several files 

rem Example with "%temp%", "%windir%\setupact.log" and "%ChromeCache%*.*"
rem AND all %windir% directory

set totalClusters=0
for %%a in ("%temp%\*.*"
            "%windir%\setupact.log"
            "%ChromeCache%*.*") do (
   set /A "totalClusters+=(%%~Za-1)/clusterSize+1"
)

for /R "%windir%" %%a in (*.*) do (
   set /A "totalClusters+=(%%~Za-1)/clusterSize+1"
)

set /A totalSizeKB=totalClusters*clusterSizeKB, totalSizeMB=totalSizeKB/1024, totalSizeGB=totalSizeMB/1024
echo Total size occupied by "%%temp%%", "%%windir%%\setupact.log" and "%%ChromeCache%%*.*" files: 
echo AND all files inside %%windir%% directory:
echo %totalSizeKB% KB  (%totalSizeMB% MB)  (%totalSizeGB% GB)

#3


2  

You should manage your files in a list/array, then you can use them for multiple operations and then it's easier to change the code in only one place for all files.

您应该在一个列表/数组中管理您的文件,然后您可以将它们用于多个操作,然后更容易地将代码更改为所有文件的一个位置。

As foxidrive mentioned, a simple addition can fail when the total filesize is above 2^31bytes, so you need a bit more advanced math there.

正如foxidrive提到的,一个简单的加法可以失败时总文件大小超过2 ^ 31个字节,所以你需要更先进的数学。

@echo off
setlocal EnableDelayedExpansion
set fileCnt=0
set totalSize=0
for %%f in (
"%userprofile%\AppData\Local\IconCache.db"
"%userprofile%\AppData\Local\GDIPFONTCACHEV1.DAT"
"%userprofile%\AppData\Local\Opera\Opera"
"%userprofile%\AppData\Local\Microsoft Corporation\Windows 7 Upgrade Advisor"
"%userprofile%\AppData\Local\Microsoft\Windows Mail\Backup"
"%userprofile%\AppData\Local\Microsoft\Windows\Explorer\thumbcache_32.db"
"%userprofile%\AppData\Local\Microsoft\Windows\Explorer\thumbcache_96.db"
) DO (
echo %%f
  set "fileList[!fileCnt!]=%%f"
  set /a totalSize+=%%~zf+0
  set /a fileCnt+=1
)

REM Now show !totalSize!

REM Now delete all files from the filelist

#1


2  

You can try something like this. As it, it will not handle cluster size, as to speed operations output of dir command is used to get the file size for each branch to avoid as much partial sums as possible. Then, size occupied by the folders itself is added to the size of the files.

你可以试试这个。由于它不会处理集群大小,所以使用dir命令的速度操作输出来获取每个分支的文件大小,以避免尽可能多的部分和。然后,将文件夹本身占用的大小添加到文件的大小。

To avoid the problem with batch arithmetic limit of 2^31 max value, a simple pen and paper sum is done. It should handle up to exabytes, but if more is needed, it is configurable.

避免与批处理算法的极限问题2 ^ 31最大价值,做一个简单的纸和笔数目。它应该处理exabytes,但是如果需要更多,它是可配置的。

@echo off
    setlocal enableextensions disabledelayedexpansion

    call :initAddSize

    call :AddSize "%temp%" "*" /s
    call :AddSize "%userprofile%\AppData\Local\Microsoft\Windows\Explorer" "thumbcache_*.db" 
    call :AddSize "c:\thisdoesnotexist" "*" /s

    call :GetTotalSize finalSize

    echo(
    echo(Total space occupied on disk: [%finalSize% bytes]
    echo(

    endlocal
    exit /b



:: AddSize
::     Recursive add file and folder sizes 

:AddSize folder [fileMask] [recurse]

    :: check if internal variables has been defined and prepare environment
    if not defined _add.total call :initAddSize
    setlocal enabledelayedexpansion

    :: Retrieve and adjust parameters
    set "folder=%~1"
    if not defined folder set "folder=%cd%"
    set "recurse="
    if /i "%~3"=="/s" (
       set "recurse=/s"
    )
    set "fileMask="
    if /i "%~2"=="/s" (
        set "recurse=/s"
    ) else (
        set "fileMask=%~2"
    )
    if not defined fileMask set "fileMask=*"

    :: If folder does not exist, nothing to do
    if not exist "%folder%\" ( endlocal & goto :eof )

    :: Size files on disk is retrieved from summary in dir command output
    :: Lines starting with at least two spaces belong to the summary

    if defined debug echo Searching files... [%folder%\%fileMask%]

    set "tempSize=0"
    for /f "tokens=3,5" %%y in (
        'dir /-c /a /w %recurse% "%folder%\%fileMask%" 2^>nul ^| findstr /b /c:"  "'
    ) do if "%%~z"=="" set "tempSize=%%~y"

    :: If files has been found, add its size 
    if not "%tempSize%"=="0" call :doAddSize %tempSize%

    :: Get the size on disk of the folders. 
    :: If recursive search is selected the sum is handled in a variable, 
    :: with periodic chekcs to avoid possible overflow in batch arithmetics.
    :: If not recursive search is selected, size of the folder is only
    :: added if all its content is selected (fileMask=*)

    if defined debug echo Sizing folders...  [%folder%]

    set "_fsz=0"
    if defined recurse (
        for /d /r "%folder%" %%z in (.) do (
            set /a "_fsz+=%%~zz"
            if !_fsz! gtr 1073741824 (
                call :doAddSize !_fsz!
                set "_fsz=0"
            )
        )
        if !_fsz! gtr 0 call :doAddSize %_fsz%
    ) else (
        if "%fileMask%"=="*" for /d %%z in ("%folder%") do call :doAddSize %%~zz
    )

    :: Calc operations done for the current folder. 
    :: Cleanup and exit

    endlocal & set "_add.total=%_add.total%"
    goto :eof


:: GetTotalSize
::     Returns the content of the internal variable used to acumulate the 
::     sucessive operations. To simplify cacls, it is stored in reverse 
::     order, so, we need to reverse it to output

:GetTotalSize [variable]
    setlocal enabledelayedexpansion
    set "_output="
    for /l %%z in (0 1 %_add.precision%) do set "_output=!_add.total:~%%z,1!!_output!"
    endlocal & if not "%~1"=="" ( set "%~1=%_output%" ) else echo(%_output%
    goto :eof


:: initAddSize
::     Initialize the internal variables used to handle output to console 
::     and to acumulate the sucessive sizes.

:initAddSize
    :: Initialize variables needed for calcs. By default "only" 20 digits will be handled
    :: in operations (10 EB) . If more or less are needed, change variable
    set "_add.total=0"
    set "_add.precision=20"
    goto :eof


:: doAddSize
::    Internal function to handle the adition of values without the problems
::    of arithmetic overflow in batch files.
::    This is nothing more than a pen and paper sum.

:doAddSize size
    setlocal enabledelayedexpansion
    set "_sz=%~1"
    set "_t=%_add.total%"
    set "_s=0"
    set "_c=0"
    set "_o="
    for /l %%z in (0 1 %_add.precision%) do (
        if defined _sz (
            set /a "_s=!_t:~%%z,1!+!_sz:~-1!+!_c!+0"
            set "_sz=!_sz:~0,-1!"
            set /a "_c=!_s!/10"
            set "_o=!_o!!_s:~-1!"
        ) else if !_c! gtr 0 (
            set /a "_s=!_t:~%%z,1!+!_c!+0"
            set /a "_c=!_s!/10"
            set "_o=!_o!!_s:~-1!"
        ) else if not "!_t:~%%z,1!"=="" set "_o=!_o!!_t:~%%z,1!"
    )
    endlocal & set "_add.total=%_o%"
    goto :eof

#2


3  

The solution to this problem is comprised of two parts.

这个问题的解决方案由两部分组成。

The minimum disk space that a file occupy on disk is a cluster, that is, all files have assigned a whole number of clusters on disk. For example, if the cluster size is 4 KB, then files from 1 to 4096 bytes occupy one cluster (4 KB), files from 4097 to 8192 bytes occupy 2 clusters (8 KB), etc. When a file is deleted, the number of clusters it occupy is released from disk, so the space recovered is generally larger than the file size; clusters always have sizes in multiples of KB. This way, in order to know the space that is recovered when files are deleted, we must know first the size of the cluster on the disk.

文件占用磁盘上的最小磁盘空间是一个集群,即所有文件都在磁盘上分配了大量集群。例如,如果集群大小为4 KB,那么文件从1到4096字节占用一个集群(4 KB),从4097年到8192字节占用2集群文件(8 KB),等。当一个文件被删除,它占领的群集的数量从磁盘被释放,所以空间恢复通常大于文件大小;集群的大小通常是KB的倍数。这样,为了了解在删除文件时恢复的空间,我们必须首先知道磁盘上集群的大小。

Although we may get the cluster size from chkdsk or fsutil commands, they have some problems in its use (like require credentials to execute them), so we will use an indirect method to get the cluster size instead: get the free space on disk, delete a small file (with size less than one cluster), and get the new free space; the difference between the two sizes is the cluster size. Please, note that very small files are stored in Windows NTFS disks using a different method, so the creation or deletion of very small files does not affect the total free space in the disk.

虽然我们可能得到chkdsk集群大小或fsutil命令,他们有其使用中存在的问题(如需要凭证执行),所以我们将使用一种间接方法来获取集群大小相反:磁盘上的*空间,删除一个小文件(大小不超过一个集群),并获得新的*空间;两种大小的区别是集群大小。请注意,非常小的文件使用不同的方法存储在Windows NTFS磁盘中,因此创建或删除非常小的文件并不会影响磁盘上的全部空闲空间。

Once you have the cluster size just get the size of each file and convert it to a number of clusters using this formula: set /A clusters=(fileSize-1)/clusterSize+1. If the cluster size is 4096 bytes, previous formula gives 1 cluster for sizes 1..4096, gives 2 clusters for sizes 4097..8192, etc. At end, multiply the total number of clusters by the size of the cluster in KB and you get the total space occupied by the files on disk, that is, the space that will be recovered when such files be deleted.

一旦您拥有了集群大小,只需获取每个文件的大小,并使用这个公式将其转换成多个集群:set / a集群=(fileSize-1)/clusterSize+1。如果集群大小为4096字节,则先前的公式将为1提供一个集群。4096,提供2个大小为4097的集群。最后,将集群的总数量乘以KB的集群大小,然后得到磁盘上文件占用的总空间,即删除这些文件时将恢复的空间。

The Batch file below is an example of previous description:

下面的批处理文件是之前描述的一个示例:

@echo off
setlocal EnableDelayedExpansion

REM FIRST PART: Get the cluster size

rem Create a file with 1000 bytes
set "line=X"
for /L %%i in (1,1,997) do set "line=!line!X"
echo %line%> temp.XYZ

rem Get free disk space with this file
for /F "tokens=3" %%a in ('dir /-C temp.XYZ') do set orig=%%a

rem Delete this file and get the new disk free space
copy nul temp.XYZ /y > NUL
for /F "tokens=3" %%a in ('dir /-C temp.XYZ') do set new=%%a
del temp.XYZ

echo New space after deleted 1000 bytes: %new%
echo Original free space:                %orig%

rem Get the cluster size
:cutFirstDigit
   set "new=%new:~1%"
   set "orig=%orig:~1%"
if "%new:~0,1%" equ "%orig:~0,1%" goto cutFirstDigit
set /A clusterSize=new-orig, clusterSizeKB=clusterSize/1024
echo/
echo Cluster size: %clusterSize% bytes (%clusterSizeKB% KB)
echo/
echo/

REM SECOND PART: Get the space occupied by several files selected by first parameter

set totalClusters=0
for %%a in (%1) do (
   set /A "totalClusters+=(%%~Za-1)/clusterSize+1"
)
set /A totalSizeKB=totalClusters*clusterSizeKB, totalSizeMB=totalSizeKB/1024, totalSizeGB=totalSizeMB/1024
echo Total size occupied by %1 files: %totalSizeKB% KB  (%totalSizeMB% MB)  (%totalSizeGB% GB)

EDIT: Reply to the comments

编辑:回复评论。

Previous code show how to "calculate the size of deleted files" given in the first parameter. Of course, you have to insert the list of the desired files instead %1 in order to calculate the total size of any files you want. For example:

前面的代码演示了如何“计算第一个参数中删除文件的大小”。当然,您必须插入所需文件的列表,而不是%1,以便计算所需文件的总大小。例如:

@echo off
setlocal EnableDelayedExpansion

REM FIRST PART: Get the cluster size

rem Create a file with 1000 bytes
set "line=X"
for /L %%i in (1,1,997) do set "line=!line!X"
echo %line%> temp.XYZ

rem Get free disk space with this file
for /F "tokens=3" %%a in ('dir /-C temp.XYZ') do set orig=%%a

rem Delete this file and get the new disk free space
copy nul temp.XYZ /y > NUL
for /F "tokens=3" %%a in ('dir /-C temp.XYZ') do set new=%%a
del temp.XYZ

rem Get the cluster size
:cutFirstDigit
   set "new=%new:~1%"
   set "orig=%orig:~1%"
if "%new:~0,1%" equ "%orig:~0,1%" goto cutFirstDigit
set /A clusterSize=new-orig, clusterSizeKB=clusterSize/1024

REM SECOND PART: Get the space occupied by several files 

rem Example with "%temp%", "%windir%\setupact.log" and "%ChromeCache%*.*"
rem AND all %windir% directory

set totalClusters=0
for %%a in ("%temp%\*.*"
            "%windir%\setupact.log"
            "%ChromeCache%*.*") do (
   set /A "totalClusters+=(%%~Za-1)/clusterSize+1"
)

for /R "%windir%" %%a in (*.*) do (
   set /A "totalClusters+=(%%~Za-1)/clusterSize+1"
)

set /A totalSizeKB=totalClusters*clusterSizeKB, totalSizeMB=totalSizeKB/1024, totalSizeGB=totalSizeMB/1024
echo Total size occupied by "%%temp%%", "%%windir%%\setupact.log" and "%%ChromeCache%%*.*" files: 
echo AND all files inside %%windir%% directory:
echo %totalSizeKB% KB  (%totalSizeMB% MB)  (%totalSizeGB% GB)

#3


2  

You should manage your files in a list/array, then you can use them for multiple operations and then it's easier to change the code in only one place for all files.

您应该在一个列表/数组中管理您的文件,然后您可以将它们用于多个操作,然后更容易地将代码更改为所有文件的一个位置。

As foxidrive mentioned, a simple addition can fail when the total filesize is above 2^31bytes, so you need a bit more advanced math there.

正如foxidrive提到的,一个简单的加法可以失败时总文件大小超过2 ^ 31个字节,所以你需要更先进的数学。

@echo off
setlocal EnableDelayedExpansion
set fileCnt=0
set totalSize=0
for %%f in (
"%userprofile%\AppData\Local\IconCache.db"
"%userprofile%\AppData\Local\GDIPFONTCACHEV1.DAT"
"%userprofile%\AppData\Local\Opera\Opera"
"%userprofile%\AppData\Local\Microsoft Corporation\Windows 7 Upgrade Advisor"
"%userprofile%\AppData\Local\Microsoft\Windows Mail\Backup"
"%userprofile%\AppData\Local\Microsoft\Windows\Explorer\thumbcache_32.db"
"%userprofile%\AppData\Local\Microsoft\Windows\Explorer\thumbcache_96.db"
) DO (
echo %%f
  set "fileList[!fileCnt!]=%%f"
  set /a totalSize+=%%~zf+0
  set /a fileCnt+=1
)

REM Now show !totalSize!

REM Now delete all files from the filelist