Results 1 to 9 of 9

Thread: FileExists

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Sep 1999
    Location
    Phoenix, az
    Posts
    1,517

    FileExists

    This works in every situation. Its the best way to do it!


    VB Code:
    1. Private Function FileExists(FullFileName As String) As Boolean
    2. On Error GoTo CheckError
    3.     If FileLen(FullFileName) = 0 Then
    4.         FileExists = False
    5.     Else
    6.         FileExists = True
    7.     End If
    8. Exit Function
    9. CheckError:
    10.     FileExists = False
    11. End Function

  2. #2
    donW
    Guest
    what is wrong with using :

    if dir(fullfilename) > "" then
    filename exists
    else
    filename dont exist
    endif

  3. #3
    Not exactly, download this file and run your test on it.

    Edit: Well the board rejected it because it was 0 bytes, and your function will fail with it.

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Sep 1999
    Location
    Phoenix, az
    Posts
    1,517
    Originally posted by filburt1
    Not exactly, download this file and run your test on it.

    Edit: Well the board rejected it because it was 0 bytes, and your function will fail with it.
    How often are you going to want to check a 0 byte file though.
    Thats my Q.
    Last edited by Evan; Dec 7th, 2001 at 05:59 PM.

  5. #5
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    How about:

    VB Code:
    1. Private Declare Function PathFileExists Lib "shlwapi.dll" Alias "PathFileExistsA" (ByVal pszPath As String) As Long
    2.  
    3. Public Function FileExists(ByVal Path As String) As Boolean
    4.     FileExists = PathFileExists(Path)
    5. End Function
    6.  
    7. 'Or you could just use it like this:
    8. dim TorF as Boolean
    9. TorF=PathFileExists(Path)

  6. #6
    jim mcnamara
    Guest
    FileExists means the file is in the directory, not how big it is.
    I create tmp files that are empty all the time, but I check for their EXISTENCE.

    Different thing, I believe.

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Sep 1999
    Location
    Phoenix, az
    Posts
    1,517
    Originally posted by jim mcnamara
    FileExists means the file is in the directory, not how big it is.
    I create tmp files that are empty all the time, but I check for their EXISTENCE.

    Different thing, I believe.
    I could see that. I think I like the API version the best so far.

  8. #8
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Actually here is a module that just has the most common FSO functions that I use only done through APIs so I don't have to distribute it.

  9. #9

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