2006-03-07, 01:22 PM
I had a very good friend of mine to come up with a vbscript that will delete the oldest recordings when you get low on hard drive space (I'm working with a 40 GB hard drive on my laptop here). He didn't want to mess with the plugin interface because he's never used Gbpvr and said that this would be much easier. He calls the the vbscript in PostProcessing.bat and the script determines how much free space you have on a drive, determines if you've reached the predetermined low disk space level, and then deletes the oldest file created in a predetermined directory. I've included the PostProcessing.bat and the AutoDelete.vbs. Please let me know what you think and if you know of any problems that I might come across. Also, if anyone wants to make it a plugin or has any suggestions on how it could be better, please go ahead and see what you can do with it.
(Also, I didn't want to use MaxRecordings because if I take this route and I end up keeping 3 recordings for every episode. What happens when my list of reoccurring recordings gets too big for my hard drive to keep 3 episodes each? I wanted it to be like his tivo, but maybe I will use a combination of the two to catch those shows that decide to have an all day marathon.)
PostProcessing.bat
AutoDelete.vbs
(Also, I didn't want to use MaxRecordings because if I take this route and I end up keeping 3 recordings for every episode. What happens when my list of reoccurring recordings gets too big for my hard drive to keep 3 episodes each? I wanted it to be like his tivo, but maybe I will use a combination of the two to catch those shows that decide to have an all day marathon.)
PostProcessing.bat
Code:
cscript AutoDelete.vbs
AutoDelete.vbs
Code:
' True means no deletes will take place
Const SAFE_MODE = True
' Minimum amount of free space or else we delete (in GB)
Const MIN_FREE_SPACE = 1.5
' Drive to check free space on
Const DRIVE = "C:"
' Path to media directory
Const MEDIA_PATH = "C:\MyVideos"
' ********************************************************
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
AutoDelete()
Sub AutoDelete()
Dim freeSpace
Dim fso
Dim fileArr
Dim delIndex
freeSpace = GetFreeSpace()
If freeSpace < MIN_FREE_SPACE Then
fileArr = GetFiles()
delIndex = 0
Do While freeSpace < MIN_FREE_SPACE And delIndex < UBound(fileArr)
freeSpace = freeSpace + BToGB(fileArr(delIndex).Size)
Delete(fileArr(delIndex))
delIndex = delIndex + 1
Loop
End If
End Sub
Function BToGB(bytes)
BToGB = bytes / 1024 / 1024 / 1024
End Function
Function GetFreeSpace()
GetFreeSpace = BToGB(fso.GetDrive(DRIVE).FreeSpace)
End Function
Function GetFiles
Dim fileArr()
Dim folder
Dim fileCount
Set folder = fso.GetFolder(MEDIA_PATH)
fileCount = 0
For Each fo In folder.SubFolders
fileCount = fileCount + fo.Files.Count
Next
ReDim fileArr(fileCount - 1)
i = 0
For Each fo In folder.SubFolders
For Each fi In fo.Files
Set fileArr(i) = fi
i = i + 1
Next
Next
QuickSort fileArr, LBound(fileArr), UBound(fileArr)
GetFiles = fileArr
End Function
Sub Delete(file)
If SAFE_MODE Then
MsgBox("AutoDelete: " & file.Name & vbCrLf & "Created: " & file.DateCreated & vbCrLf & "Size: " & BToGB(file.Size) & "GB")
Else
File.Delete
End If
End Sub
Sub QuickSort(Arr, First, Last)
Dim Pivot
If First < Last Then
Pivot = Partition(Arr, First, Last)
QuickSort Arr, First, Pivot - 1
QuickSort Arr, Pivot + 1, Last
End If
End Sub
Function Partition(Arr, First, Last)
Dim x, i, j
Dim swap
Set x = Arr(First)
i = First + 1
j = Last
Do While i <= j
Do While i <= j
If Arr(j).DateCreated <= x.DateCreated Then Exit Do
j = j - 1
Loop
Do While i <= j
If Arr(i).DateCreated > x.DateCreated Then Exit Do
i = i + 1
Loop
If i < j Then
Set swap = Arr(i)
Set Arr(i) = Arr(j)
Set Arr(j) = swap
i = i + 1
j = j - 1
End If
Loop
Set Arr(First) = Arr(j)
Set Arr(j) = x
Partition = j
End Function