biglebowski
Technical User
I have a script to delete all WAV files older than 365 days in a specific folder and subfolders. The file structure of the folder is
E:\Audio\Date\Machine\Channel\xxxxx.WAV
The script runs without errors but does not delete anything, am I missing something simple here?
Also is it possible to delete all the folders as well?
When I was born I was so suprised I didn't talk for 18 months
E:\Audio\Date\Machine\Channel\xxxxx.WAV
The script runs without errors but does not delete anything, am I missing something simple here?
Also is it possible to delete all the folders as well?
Option Explicit
Dim arExtensions
arExtensions = Array("wav")
DelByAgeAndExtension "E:\Audio","365","c",arExtensions
Function DelByAgeAndExtension(strFolder,strDaysOld, strCreateOrMod,
arExtensions)
Dim fso, wshShell, objFolder, colFiles, colSubFolders, objFile,
subFolder
Set fso = CreateObject("Scripting.FileSystemObject")
Set wshShell = CreateObject("Wscript.Shell")
Set objFolder = fso.GetFolder(strFolder)
Set colFiles = objFolder.Files
Set colSubFolders = objFolder.SubFolders
'delete files matching extension in parent folder
On Error Resume Next
For Each objFile In colFiles
DelFileByExtension objFile, strDaysOld,arExtensions, strCreateOrMod
Next
'delete files matching extensions in each sub folder
For Each subFolder In colSubFolders
Set colFiles = subFolder.Files
For Each objFile In colFiles
DelFileByExtension objFile,strDaysOld,arExtensions, strCreateOrMod
Next
Next
End Function
Function GetFileCreatedAgeInDays(objFile)
Dim fso, objCheckFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set objCheckFile = fso.GetFile(objFile)
GetFileCreatedAgeInDays = (Now - objCheckFile.DateCreated)
End Function
Function GetFileModifiedAgeInDays(objFile)
Dim fso, objCheckFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set objFile = fso.GetFile(objFile)
GetFileModifiedAgeInDays = (Now - objFile.DateLastModified)
End Function
Sub DelFileByExtension(objFile,strDaysOld,arExtensions,strCreateOrMod)
Dim i
For i = 0 To UBound(arExtensions)
If LCase(Right(objFile.ShortName,3)) = LCase(arExtensions(i)) Then
'if strDaysOld set to -1 then delete all files
'matching extension regardless of age
If strDaysOld = "-1" Then
objFile.Delete
Else
If strCreateOrMod = "C" Then
If GetFileCreatedAgeInDays(objFile) >= Int(strDaysOld) Then
objFile.Delete
End If
Else 'deletes based on modified date if strDaysOld is anything _
other than "C"
If GetFileModifiedAgeInDays(objFile) >= Int(strDaysOld) Then
objFile.Delete
End If
End If
End If
End If
Next
End Sub
When I was born I was so suprised I didn't talk for 18 months