Question

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.

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

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
Was it helpful?

Solution 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.

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.

@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

OTHER TIPS

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.

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.

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.

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:

@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)

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.

@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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top