I've written a vbs script to try delete all files over a certain age from pre-defined subfolders within a directory.
These subfolders are defined in a configuration file:
[folders]
des
dcs
I'm trying to load this data into a VBS script during runtime. The config file will be located in the same folder as the VBS script, in a subfolder called Config
.
I basically want the values under [folder
] stored in an array. Below is an example where I've hardcoded this using the variable codes
.
Can someone please assist?
Set oFileSys = WScript.CreateObject("Scripting.FileSystemObject")
sRoot = "C:\project\Target"
today = Date
nMaxFileAge = 3
codes = Array("des", "dcs") 'hardcoded for now
For Each code in codes
textFilePath = oFileSys.BuildPath(sRoot, code)
remove_files(textFilePath)
Next
Function remove_files(path)
Set oFolder = oFileSys.GetFolder(path)
Set aFiles = oFolder.Files
Set aSubFolders = oFolder.SubFolders
For Each file in aFiles
dFileCreated = FormatDateTime(file.DateCreated, "2")
if DateDiff("d", dFileCreated, today) > nMaxFileAge Then
file.Delete(True)
End If
Next
For Each folder in aSubFolders
remove_files(folder.Path)
Next
End Function
Edit: It doesn't really matter what type of file the configuration file is. Just somewhere I can define a list of folder and read it into VBS.
The answer someone else has linked to before closing my question doesn't answer the question. See my solution below.