Results 1 to 10 of 10
  1. #1
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919

    Filelen (a member of the FileSystem object)


    Using an existing file, whose length in bytes is reported by Windows Explorer as being 3,602,242KB, the Filelen function returns -606272000. Filelen returns "Long" and that's how I've treated in code.

    Can anyone explain what it is that I'm seeing with -606272000 versus what WE displays?

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,424
    3,602,242KB is 3,602,242,000 bytes. The maximum size of a long is 2,147,483,647 so you are out of range

    there is a link here about the issue with a workaround

    https://ask.libreoffice.org/en/quest...ile-sizes-4gb/

    more suggestions here

    http://vbadud.blogspot.co.uk/2007/05/get-file-size.html

  3. #3
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    Yes, I wondered about that. I ran the function suggested in the workaround and received 3,688,695,296 as the length of the file described in the initial post. One would then have to divide by 1024 to approximate what is reported by Windows Explorer. My need is satisfied by the actual byte count returned by the function.

    Thanks,
    Bill

  4. #4
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,424
    oops, my bad, yes 1024, not 1000. So 3,602,242KB is 3,688,695,808 bytes. The difference between this and your answer is probably due to the KB figure being rounded

  5. #5
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    Doesn't work for very large files. The test case I used here is an Acronis tib file of an SDD image that Windows Explorer reports as being 92,962,524KB.

    Code:
    Option Compare Database
    Option Explicit
    Private Sub testing()
    MsgBox dFileSizeInKb("U:\Off(1) IMAGE-Sunday_full_b70_s1_v1.tib")
    End Sub
    Function dFileSizeInKb(sMediaFilePath) As Double
    Dim dMediaFileLength As Double
                
    dMediaFileLength = FileLen(sMediaFilePath)
    
        If dMediaFileLength < 0 Then
            dMediaFileLength = 2 ^ 32 + dMediaFileLength
            MsgBox dMediaFileLength
        End If
    
    dFileSizeInKb = dMediaFileLength
    
    End Function

  6. #6
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,424
    have you tried this?

    Code:
    Debug.Print CreateObject("scripting.filesystemobject").GetFile("U:\Off(1) IMAGE-Sunday_full_b70_s1_v1.tib").Size
    no idea if it works for very large files, but would be interested to know

  7. #7
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    Code:
    CreateObject("scripting.filesystemobject").GetFile("U:\Off(1) IMAGE-Sunday_full_b70_s1_v1.tib").Size
    Yields: 95193624576 (/1024 = 92,962,524KB which is exactly what WE reports)

  8. #8
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    I will add the tested statement into my code and monitor the results on Tuesday following Monday night's Acronis run of a full image backup on one of my systems that produces a tib file more in the range of 35GB. (Nothing like seeing if production runs go as well as test runs......... )

  9. #9
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,424
    Yields: 95193624576 (/1024 = 92,962,524KB which is exactly what WE reports)
    so it works then

  10. #10
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    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.)

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 07-20-2017, 07:20 AM
  2. Replies: 4
    Last Post: 05-02-2016, 04:33 AM
  3. Replies: 3
    Last Post: 05-21-2014, 10:15 AM
  4. Replies: 1
    Last Post: 09-03-2011, 07:01 PM
  5. Replies: 1
    Last Post: 08-05-2010, 12:11 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums