Results 1 to 5 of 5

Thread: checking if a file exsits

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715

    Red face

    can somone please tell me how to cheack if a file exsits.
    please make it as simple as possible becuase I'm still sleeping although its 2:10 in Rhode Island
    NXSupport - Your one-stop source for computer help

  2. #2
    Hyperactive Member
    Join Date
    May 2000
    Location
    Or
    Posts
    316
    Try this:

    Code:
    Dim fso
    
    Set fso=CreateObject("Scripting.FileSystemObject")
    
    If fso.FileExists("c:\windows\desktop\myFile.txt")=True then
       msgbox "I'm here"
    Else
       msgbox "File not present"
    end if

  3. #3
    Guest
    Code:
    Function VBDoesFileExist(FilePath As String) As Boolean
        On Error Resume Next
        Dim strRet As String
    ' see if the file exists
        strRet = Dir$(FilePath, vbNormal Or vbSystem Or vbHidden Or vbReadOnly)
    
    ' check to make sure the handle isnt invalid
    
        If strRet <> "" Then
            VBDoesFileExist = True
        Else
            VBDoesFileExist = fale
        End If
    
    ' use:
    ' VBDoesFileExist(c:\windows\desktop\myilfe.txt)
    End Function
    this is better because it doesnt require the reference to the scripting host.

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715
    whats the diffrence? to me one is longer, one is shorter.

    Sorry, if I'm dont getting it right now becuase I am tried, the first one seems simple any easy for me.
    NXSupport - Your one-stop source for computer help

  5. #5
    Guest
    You can use the Dir Function.

    Code:
    RetVal = Dir("C:\MyFile")
    
    If RetVal <> "" Then
        MsgBox ("File Exsists")
    Else
        MsgBox ("File Does not exsist")
    End If

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