
passing arguments to sub - script not working as expected
Mike,
It's good practice to explicity specify whether parameters are passed ByVal
or ByRef in all your function declarations. VB 6.0 and VBScript default to
ByRef, but VB.NET now defaults to ByVal.
Is your F: drive mapped properly?
Gordon Bell
'purpose: deletes all files from a specified folder not modified in the
last x days
dim TargetFolder
dim BufferDays
dim ForceReadOnly
'first call -----------------------
TargetFolder = "F:\SharePoint Technologies\database_backups"
BufferDays = 0 'x days to keep backed up; 0 will delete the ENTIRE
directory's contents
ForceReadOnly = TRUE 'boolean argument to force deletion of read only files
Call DeleteOldBackups(TargetFolder, BufferDays, ForceReadOnly)
'second call --------------------------
TargetFolder = "\\is034\sharepoint-backup\database_backups"
BufferDays = 7 'x days to keep backed up
ForceReadOnly = TRUE 'boolean argument to force deletion of read only files
Call DeleteOldBackups(TargetFolder, BufferDays, ForceReadOnly)
Sub DeleteOldBackups(ByVal TargetFolder, ByVal BufferDays, ByVal
ForceReadOnly)
set fso = CreateObject("Scripting.FileSystemObject") 'Initializes a
File System Object
set fldr = fso.GetFolder(TargetFolder) 'places the target folder in the
File System Object
set myfiles = fldr.files 'returns all of the files in the target folder
for each indfile in myfiles
if indfile.DateLastModified < (Now() - BufferDays) then
indfile.Delete (ForceReadOnly)
end if
next
set fso = nothing
set fldr = nothing
set myfiles = nothing
set indfile = nothing
end sub
wscript.quit
Hi there,
My script is below.. I'm trying to pass 3 arguments to a sub; two different
calls. I can only get the second call to the sub to work if I comment out
the four lines of the first call.. I don't know if arguments are passed by
ref or value or if it is something entirely different causing this not to
work. Also, this script is triggered by the 'Task, Scheduler' and once
started, appears as 'running' until I stop it.. Another mystery.. Any help
is greatly appreciated.
TIA,
Mike D.
-------------------------------------------------------------------
'purpose: deletes all files from a specified folder not modified in the
last x days
dim TargetFolder
dim BufferDays
dim ForceReadOnly
'first call -----------------------
TargetFolder = "F:\SharePoint Technologies\database_backups"
BufferDays = 0 'x days to keep backed up; 0 will delete the ENTIRE
directory's contents
ForceReadOnly = TRUE 'boolean argument to force deletion of read only files
Call DeleteOldBackups(TargetFolder, BufferDays, ForceReadOnly)
'second call --------------------------
TargetFolder = "\\is034\sharepoint-backup\database_backups"
BufferDays = 7 'x days to keep backed up
ForceReadOnly = TRUE 'boolean argument to force deletion of read only files
Call DeleteOldBackups(TargetFolder, BufferDays, ForceReadOnly)
sub DeleteOldBackups(TargetFolder, BufferDays, ForceReadOnly)
set fso = CreateObject("Scripting.FileSystemObject") 'Initializes a File
System Object
set fldr = fso.GetFolder(TargetFolder) 'places the target folder in the
File System Object
set myfiles = fldr.files 'returns all of the files in the target folder
for each indfile in myfiles
if indfile.DateLastModified < (Now() - BufferDays) then
indfile.Delete (ForceReadOnly)
end if
next
set fso = nothing
set fldr = nothing
set myfiles = nothing
set indfile = nothing
end sub
wscript.quit