I have read the notes on how to read in variables from a command line.
I have tried different versions of code and I cannot see to get it to work.
Please help - what is wrong with the code? The orginal code came from Mark (?) to cleanup log files in Windows. I would like one generic program and be able to feed variables in.
This question is urgent - I'm positive that it isn't hard.
Here is the code . . .
Private Sub Form_load()
Dim path As String
Dim killextension As String
Dim killdate As Integer
Dim parameter as Variant
parameter = Split(Command())
path = parameter(0)
killextension = parameter(1)
killdate = date - parameter(2)
' folder to start search in...
' path = "c:\janet"
' delete files with this extension...
' killextension = "txt"
' delete files older than 7 days...
' killdate = date() - 30
arFiles = Array()
set fso = createobject("scripting.filesystemobject")
' Don't do the delete while you still are looping through a
' file collection returned from the File System Object (FSO).
' The collection may get mixed up.
' Create an array of the file objects to avoid this.
SelectFiles path, killdate, arFiles, true
nDeleted = 0
for n = 0 to ubound(arFiles)
' Files deleted via FSO methods do *NOT* go to the recycle bin!!!
on error resume next 'in case of 'in use' files...
if err.number <> 0 then
wscript.echo "Unable to delete: " & arFiles(n).path
nDeleted = nDeleted + 1
on error goto 0
msgbox nDeleted & " of " & ubound(arFiles)+1 _
& " eligible files were deleted"
on error resume next
'select files to delete and add to array...
set folder = fso.getfolder(sPath)
set files = folder.files
for each file in files
' uses error trapping around access to the
' Date property just to be safe
dtlastmodified = null
on error resume Next
dtlastmodified = file.datelastmodified
on error goto 0
if not isnull(dtlastmodified) Then
if dtlastmodified < vKillDate and _
lcase(fso.getextensionname(file)) = lcase(killExtension) Then
count = ubound(arFilesToKill) + 1
redim preserve arFilesToKill(count)
set arFilesToKill(count) = file
' if bIncludeSubFolders then
' for each fldr in folder.subfolders
' SelectFiles fldr.path,vKillDate,arFilesToKill,true
' end if