我是bat脚本新手,需要满足以下要求:
如果目录(如C:\test size)超过50GB,则脚本应删除最旧的文件,直到目录大小恢复到50GB或略小。
我已修改了在上找到的以下脚本
Get size of a directory in 'MB' using batch file
但我不确定如何继续执行其余的要求。请参阅我迄今为止所做的小修改,如有任何意见,我将不胜感激:
@echo off
set limit="50.0"
set Folder="C:\test"
echo The size of %Folder% is
Call :GetSize %Folder%
IF /I "Call :GetSize %Folder%" GEQ "50.0" Echo Overlimit
<Here I would like to delete oldest zip files until the folder size is back to <=50.0GB>
pause
:GetSize
(
echo wscript.echo GetSize("%~1"^)
echo Function GetSize(MyFolder^)
echo Set fso = CreateObject("Scripting.FileSystemObject"^)
echo Set objFolder= fso.GetFolder(MyFolder^)
echo GetSize = FormatSize(objFolder.Size^)
echo End Function
echo '*******************************************************************
echo 'Function to format a number into typical size scales
echo Function FormatSize(iSize^)
echo aLabel = Array("bytes", "KB", "MB", "GB", "TB"^)
echo For i = 0 to 4
echo If iSize ^> 1024 Then
echo iSize = iSize / 1024
echo Else
echo Exit For
echo End If
echo Next
echo FormatSize = Round(iSize,2^)
echo End Function
echo '*******************************************************************
)>%tmp%\Size.vbs
Cscript /NoLogo %tmp%\Size.vbs
Del %tmp%\Size.vbs
Exit /b