CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: existing files

  1. #1
    Join Date
    Jun 2000
    Posts
    41

    existing files

    Is there a way to tell if a certain file exists? Like a function or something? Perhaps:

    FileExist("c:\Windows\whatever.txt")



    Any help is appreciated.


  2. #2
    Join Date
    Apr 2000
    Posts
    737

    Re: existing files

    refer
    http://vblib.virtualave.net

    there is a function IsFileExist in vbFileIO class,

    hope this help.


  3. #3
    Join Date
    Mar 1999
    Location
    Nepal
    Posts
    540

    Re: existing files

    If you know the path of the file, you can use the Dir$ function to check whether the file exists.


  4. #4
    Join Date
    Feb 2001
    Location
    Stamford CT USA
    Posts
    2,167

    Re: existing files

    And the code looks a bit like this:

    function IsFileExist(szFileName as string) as boolean
    ' default to not exist
    IsFileExist = false
    if (dir(szFileName, vbNormal) <> "") then
    ' found it
    IsFileExist = true
    end if
    end function




    -Cool Bizs

    Good Luck,
    -Cool Bizs

  5. #5
    Join Date
    Mar 1999
    Location
    Nepal
    Posts
    540

    Re: existing files

    Yes, and a one line solution as follows:

    function IsFileExist(szFileName as string) as boolean
    IsFileExist = (dir(szFileName, vbNormal) <> "")
    End Function





  6. #6
    Join Date
    Jun 2000
    Posts
    41

    Re: existing files

    Thanks a lot. It really helped.


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

Featured