FOR WHATEVER IT MIGHT BE WORTH................
This thread dealt with the issue of obtaining file lengths in code attempting to use the "FileLen" member of the "File System Object". In the present situation, I am dealing with Acronis tib files that tend to become quite large, especially when a disc image is created. Ajax came up with the solution and I'm posting the code segment that employs his method.
Code:
Private Sub CopyOp(FilePrefix As String)
'*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=**=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
' Make copies of the Acronis backup files from the NAS to the "Go Bag" USB drive on the office host.
'*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=**=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
Dim NASFile As String 'Name of the candidate file on the NAS
Dim QNASFile As String 'Fully qualified file name found on NAS
Dim NASFileLen As Double 'Length of file found on NAS
Dim USBFile As String 'Name of any found USB tib file
Dim QUSBFILE As String 'Fully qualified file name found on USB
Dim USBFileLen As Double 'Length of whatever file is found on USB
Dim strLen As String 'Formatted string for log and notification messages
On Error GoTo CopyOpError
NASFile = Dir(NASLocation & FilePrefix & "(" & BkUpDay & ")*.tib")
USBFile = Dir(USBLocation & FilePrefix & "(" & BkUpDay & ")*.tib")
If NASFile = "" Then
Write #1, Date & " " & Time() & "No tib file found for " & FilePrefix & "(" & BkUpDay & ")"
End If
Write #1, Date & " " & Time() & " Copying file: " & NASFile
QNASFile = NASLocation & NASFile
NASFileLen = CreateObject("Scripting.FileSystemObject").GetFile(QNASFile).Size 'lengh of NAS tib file in bytes
If USBFile <> "" Then 'Is there a USB file for "BkUpDay"?
QUSBFILE = USBLocation & USBFile 'Yes, qualify its location and get its length
USBFileLen = CreateObject("Scripting.FileSystemObject").GetFile(QUSBFILE).Size
End If
' Check to see if copy has already been done?
If (USBFile = NASFile) And (USBFileLen = NASFileLen) Then
strLen = Format(USBFileLen / 1024, "###,###,###") & "MB"
LogMsg = Date & " " & Time() & NASFile & " (" & strLen & ") " & " found already existing..... We are good."
Write #1, LogMsg
Else
If USBFile <> "" Then Kill (QUSBFILE) 'Delete previous copy
'Copy From NAS to the USB 3.0 disc
QUSBFILE = USBLocation & NASFile 'Give copy the exact same name
FileCopy QNASFile, QUSBFILE 'Start the copy operation
USBFileLen = CreateObject("Scripting.FileSystemObject").GetFile(QUSBFILE).Size 'Get size of the new copy
If USBFileLen <> NASFileLen Then
Write #1, "Source length (" & NASFileLen & ") NOT EQUAL to copy length (" & USBFileLen & ")."
Else
strLen = Format(USBFileLen / 1024, "###,###,###") & "MB"
LogMsg = Date & " " & Time() & " File " & NASFile & " (" & strLen & ") Copied successfully."
Write #1, LogMsg
End If
End If
LogText = LogText & LogMsg & vbNewLine
EndLog:
Write #1, Date & " " & Time() & " Copy Opertion Completed" & vbNewLine
Exit Sub
CopyOpError:
MsgBox "CopyOp Error: " & Err.Number & " " & Err.Description
GoTo EndLog
End Sub
(As a side note, I'm located in the heavy forests of the Sierra where one must always be concerned about fire danger and the necessity of maintaining what is commonly referred to as a "Go Bag" that can be scooped up during an evacuation. In my case, I grab among other things a USB drive that contains the images and data for all the systems on my network. For reasons I won't get into, I don't use Internet cloud storage.)