星期五, 3月 08, 2013

[Windows batch] Delete file script when disk space is less than 1 TB

@setlocal enableextensions enabledelayedexpansion
@echo off

goto detect

:del_files
echo "
Hard Disk Space is less than 1TB , Now delete temp files..."    
Rem Customize your forfiles scripts body
Rem For example , under E:\backupdir directory ,
 delete files older than 55 days
forfiles.exe -p "E:\backupdir" -s -m file_name_* -D -55 -c "cmd /c del @FILE"
goto end

:detect
for /f "tokens=3" %%a in ('dir E:\') do (
    set bytesfree=%%a

)
set bytesfree=%bytesfree:,=%
echo The bytes free is : %bytesfree%
endlocal && set bytesfree=%bytesfree%

if %bytesfree% GTR 1099511627776 echo "Hard Disk Space is greater than 1TB ~! "
if %bytesfree% GTR 1099511627776 goto del_files
goto end


:end
echo good bye


沒有留言:

LinkWithin-相關文件

Related Posts Plugin for WordPress, Blogger...