hard.vbs
Set fsoobj = CreateObject("Scripting.FileSystemObject")
DriversInfo = GetDriversInfo
DriversInfo = Replace(DriversInfo, "|", vbCrLf)
sReturn = vbCrLf & DriversInfo
Wscript.Echo sReturn
Function GetDriversInfo()
GetDriversInfo = ""
Set drvObj = fsoobj.Drives
For Each D In drvObj
Err.Clear
If D.DriveLetter <> "A" Then
If D.isReady Then
'检查C盘剩余空间,如果需要检查其他磁盘,请修改盘符
If D.DriveLetter = "D" Then
GetDriversInfo = GetDriversInfo & "partition:" & D.DriveLetter & vbCrLf
GetDriversInfo = GetDriversInfo & "Total:" & cSize( D.TotalSize) & vbCrLf
GetDriversInfo = GetDriversInfo & "Use:" & Int((100*((D.TotalSize-D.FreeSpace)/D.TotalSize))) &" %" & vbCrLf
GetDriversInfo = GetDriversInfo & "Available space:" & cSize(D.FreeSpace) & vbCrLf
GetDriversInfo = GetDriversInfo & "|"
End If
Else
End If
Else
End If
Next
End Function
Function cSize(tSize)
If tSize >= 1073741824 Then
cSize = Int((tSize / 1073741824) * 1000) / 1000 & " GB"
ElseIf tSize >= 1048576 Then
cSize = Int((tSize / 1048576) * 1000) / 1000 & " MB"
ElseIf tSize >= 1024 Then
cSize = Int((tSize / 1024) * 1000) / 1000 & " KB"
Else
cSize = tSize & "B"
End If
End Function
checkdisk.bat
@echo off
set _info=info.txt
set _interval=5000
set _threshold=5547.9
:checkstart
del %_info%
cscript //Nologo hard.vbs >> %_info%
set filePath= %_info%
for /f "delims=" %%i in (%filePath%) do (
set lastLine=%%~i
)
echo %lastLine%
for /F "tokens=1,2,3 delims=: " %%a in ("%lastLine%") do (
::echo %%a
echo %%c
rem 如果磁盘空间大于或等于70GB,进入休眠;否则进入处理程序
if %%c geq %_threshold% (
echo greater than
goto checkag
) else (
echo less than
goto doSomething
)
)
:doSomething
echo dosomthong
:checkag
echo %time% program %_task% run normally, next check will be lauched in %_interval% milliseconds ...
echo Wscript.Sleep WScript.Arguments(0) >%tmp%\delay.vbs
cscript //b //nologo %tmp%\delay.vbs %_interval%
goto checkstart
另一种实现延时的实现
@echo off
set _info=info.txt
set _interval=5000
set _threshold=5547.9
set _delaytime=5
:checkstart
del %_info%
cscript //Nologo hard.vbs >> %_info%
set filePath= %_info%
for /f "delims=" %%i in (%filePath%) do (
set lastLine=%%~i
)
echo %lastLine%
for /F "tokens=1,2,3 delims=: " %%a in ("%lastLine%") do (
::echo %%a
echo %%c
rem 如果磁盘空间大于或等于70GB,进入休眠;否则进入处理程序
if %%c geq %_threshold% (
echo greater than
goto checkag
) else (
echo less than
goto doSomething
)
)
:doSomething
echo dosomthong
:checkag
echo %time% program %_task% run normally, next check will be lauched in %_interval% milliseconds ...
rem echo Wscript.Sleep WScript.Arguments(0) >%tmp%\delay.vbs
rem cscript //b //nologo %tmp%\delay.vbs %_interval%
timeout /t %_delaytime% /NOBREAK
goto checkstart
参考