Results 1 to 8 of 8

Thread: Detecting Empty Files

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2002
    Location
    Australia
    Posts
    30

    Question Detecting Empty Files

    Hi,

    I am having trouble detecting an empty file opened in Binary mode. I have tried the following function and it always returns false.

    Code:
    Public Function fnEmptyFile (ByVal strPath as String)
         Dim FileHandle%
    
         FileHandle% = FreeFile
         Open strPath For Binary Access Read Write As #FileHandle%
    
         If (EOF(FileHandle%) = True) then
              fnEmptyFile = True
         else
              fnEmptyFile = False
         End If
    
         Close #FileHandle%
    
    End Function
    Does anyone have any suggestions as to how to detect an empty file?

    Thanks

    MechEngCoder

  2. #2

    Thread Starter
    Junior Member
    Join Date
    Nov 2002
    Location
    Australia
    Posts
    30
    Sorry forgot the As Boolean in the function header, typo

  3. #3
    PowerPoster
    Join Date
    Aug 2001
    Location
    new jersey
    Posts
    2,904
    there's got to be a method somewhere (FSO, maybe?) that gives you the file size, so you could just look for size=0

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Nov 2002
    Location
    Australia
    Posts
    30

    Question

    Thanks, does anyone know the method could not see under FSO?

  5. #5
    PowerPoster
    Join Date
    Aug 2001
    Location
    new jersey
    Posts
    2,904
    in the same scripting library that contains the FSO there is a "file" object that has a "size" property

  6. #6
    Frenzied Member Blobby's Avatar
    Join Date
    Oct 2001
    Location
    England
    Posts
    1,512
    You can just use the Filelen function.
    VB Code:
    1. if Filelen(Filepathandname) = 0 then
    2.  'file is empty
    3. endif
    There are 3 types of people in this world.........those that can count, and those that can't.

    Blobby

  7. #7
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803
    After you open the file, you can use "LOF(#FileHandle%)"

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Nov 2002
    Location
    Australia
    Posts
    30
    Thanks works a Treat

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width