Hello all I've been making great strides since using this forum with many technologies and want to again express my appreciation to responses to the questions.
I was able to get this script to work where it backs up the parent and sub folders. I also need to scann the source folder for files older than 30 days and delete them.
I sucessfully scripted the file deletion block of code and it works well when I run it outside of the backup bloack of code.
Please see the portion of this script in red which is giving me the "Invalid procedure call or argument"
'Option Explicit
'On error resume next
Dim objFso, objFolder, objFile, FolderPath, i, Logfile
FolderPath = "C:\"
FolderPrefix = "PPress"
sfolder = "C:\PPress\"
dFolder = "PPressBak"
Const OverWriteFiles = True
Set objFso = CreateObject("Scripting.fileSystemObject")
i = "0" & (Month(Now)) & "-" & (Year(Now))
'WScript.Echo sfolder & dFolder & i
WScript.Echo i
If objFso.FolderExists(FolderPath & dfolder & i) = False Then
Wscript.echo("Create new folder and for updating")
ObjFso.CreateFolder(FolderPath & dfolder & i)
WScript.Sleep 500
ObjFSO.CopyFolder sFolder, FolderPath & dFolder & i 'OverWriteFiles
Wscript.Echo("Ending Copy" & " " & Now)
Else
'Verify file and folder paths to move through script)
'WScript.Echo(objFolder)
Wscript.echo(folderPath & dfolder & i & " Folder Created")
Wscript.sleep 500
Wscript.echo(sfolder)
Wscript.echo(dfolder)
sFolder = "C:\PPress"
dFolder = "C:\PPressBak"
Set objFso = CreateObject("Scripting.filesystemObject")
objFSO.CopyFolder sFolder, dFolder & i, OverWriteFiles
Wscript.Echo("Ending Copy" & " " & Now)
End If
WScript.Echo("Call purging subroutine for daily cleanup")
Set logfile = objFSO.CreateTextFile(LogFilePath & "\DelFiles.Log", True)
GetFiles strFolder
Sub GetFiles(ByVal sFolder)
Set objFso = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFso.GetFolder(sfolder)
logfile.Write "Directory Name: " & objFolder.Path & VbCrLf
logfile.Write "Date: " & Now() & VbCrLf & VbCrLf
For Each objFile in objFolder.Files
If objfile.DateLastModified < PurgeDate Then
intFileCount = intFileCount + 1
logfile.Write "File: " & objFile.Name & vbTab & intFileCount & vbTab _
& objFile.DateLastModified & VbCrLf
logfile.Write VbCrLf
'WScript.Echo("The files listed are more than 30 days old and will be deleted" & objFile.Path)
objFSO.DeleteFile(objFile)
End If
Next
For each objFolder in objFolder.SubFolders
GetFiles objFolder.Path
Next
End Sub
I was able to get this script to work where it backs up the parent and sub folders. I also need to scann the source folder for files older than 30 days and delete them.
I sucessfully scripted the file deletion block of code and it works well when I run it outside of the backup bloack of code.
Please see the portion of this script in red which is giving me the "Invalid procedure call or argument"
'Option Explicit
'On error resume next
Dim objFso, objFolder, objFile, FolderPath, i, Logfile
FolderPath = "C:\"
FolderPrefix = "PPress"
sfolder = "C:\PPress\"
dFolder = "PPressBak"
Const OverWriteFiles = True
Set objFso = CreateObject("Scripting.fileSystemObject")
i = "0" & (Month(Now)) & "-" & (Year(Now))
'WScript.Echo sfolder & dFolder & i
WScript.Echo i
If objFso.FolderExists(FolderPath & dfolder & i) = False Then
Wscript.echo("Create new folder and for updating")
ObjFso.CreateFolder(FolderPath & dfolder & i)
WScript.Sleep 500
ObjFSO.CopyFolder sFolder, FolderPath & dFolder & i 'OverWriteFiles
Wscript.Echo("Ending Copy" & " " & Now)
Else
'Verify file and folder paths to move through script)
'WScript.Echo(objFolder)
Wscript.echo(folderPath & dfolder & i & " Folder Created")
Wscript.sleep 500
Wscript.echo(sfolder)
Wscript.echo(dfolder)
sFolder = "C:\PPress"
dFolder = "C:\PPressBak"
Set objFso = CreateObject("Scripting.filesystemObject")
objFSO.CopyFolder sFolder, dFolder & i, OverWriteFiles
Wscript.Echo("Ending Copy" & " " & Now)
End If
WScript.Echo("Call purging subroutine for daily cleanup")
Set logfile = objFSO.CreateTextFile(LogFilePath & "\DelFiles.Log", True)
GetFiles strFolder
Sub GetFiles(ByVal sFolder)
Set objFso = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFso.GetFolder(sfolder)
logfile.Write "Directory Name: " & objFolder.Path & VbCrLf
logfile.Write "Date: " & Now() & VbCrLf & VbCrLf
For Each objFile in objFolder.Files
If objfile.DateLastModified < PurgeDate Then
intFileCount = intFileCount + 1
logfile.Write "File: " & objFile.Name & vbTab & intFileCount & vbTab _
& objFile.DateLastModified & VbCrLf
logfile.Write VbCrLf
'WScript.Echo("The files listed are more than 30 days old and will be deleted" & objFile.Path)
objFSO.DeleteFile(objFile)
End If
Next
For each objFolder in objFolder.SubFolders
GetFiles objFolder.Path
Next
End Sub