Ok Issues I'm having before posting my code... I'm getting this error
Error: Object Required; 'objDIR' Code: 800A01A8 On line 19
When I skip over it using On Error Resume Next and On Error GoTo 0 I get Error Object required: 'strFile' Line 22 When I skip over that It tells me that my last NEXT is not a collection... Here's the thing the program worked beautifully Until I added in the steps for getting .tif and .tiff files. Now even If I remove what I added it doesn't work...
The function of this program is to search a "source directory" for files that are archivable it then moves those files to "Destination Directory" and then checks them as unarchivable so that they aren't picked up a second time around. It also make a log of what files were copied with date stamps etc. Like I said it worked great but after tinkering for hours cant figure out what went wrong...
Option Explicit
Dim objLogFile, objFS, strFolder, strDestination, objFolder, eFolder, strFileName,
strExtension, objDIR, strFile
Set objFS = CreateObject("Scripting.FileSystemObject")
strFolder = "S:\Source"
strDestination = "Z:\Destination"
Set objFolder = objFS.GetFolder(strFolder)
Set objLogFile = objFS.OpenTextFile ("S:\Log.txt",2,true)
Go(objFolder)
Sub Go(objDIR)
objLogFile.Writeline "Script started at " & Now
If objDIR <> "\System Volume Information" Then
For Each eFolder In objDIR.SubFolders
Go eFolder
Next
On Error Resume Next
For Each strFile In objDIR.Files
On Error GoTo 0
strFileName = strFile.Name
strExtension = objFS.GetExtensionName(strFile)
If strExtension = "pdf" Then
If objFS.GetFile(strFile).Attributes And 32 Then
objFS.CopyFile strFile , strDestination & strFileName, True
objLogFile.Writeline "Copied " & strFileName & Now
Else
objFS.GetFile(strFile).Attributes = objFS.GetFile(strFile).Attributes XOR 32
End If
End If
If strExtension = "tif" Then
If objFS.GetFile(strFile).Attributes And 32 Then
objFS.CopyFile strFile , strDestination & strFileName, True
objLogFile.Writeline "Copied " & strFileName & Now
Else
objFS.GetFile(strFile).Attributes = objFS.GetFile(strFile).Attributes XOR 32
End If
End If
If strExtension = "tiff" Then
If objFS.GetFile(strFile).Attributes And 32 Then
objFS.CopyFile strFile , strDestination & strFileName, True
objLogFile.Writeline "Copied " & strFileName & Now
Else
objFS.GetFile(strFile).Attributes = objFS.GetFile(strFile).Attributes XOR 32
End If
End If
Next
objFS.GetFile(strFile).Attributes = objFS.GetFile(strFile).Attributes XOR 32
End If
objLogFile.Writeline "Script ended at " & Now
objLogFile.close
WScript.Quit()
End Sub