Results 1 to 8 of 8

Thread: FileExists:

  1. #1

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    FileExists:

    Just wondering, how do you check if a directory exists? i thought it was like
    VB Code:
    1. Private Sub Form_Load()
    2.     If FileExists(App.Path & "\yay.dir") Then
    3.         Print vbNullString
    4.     Else
    5.         MsgBox ("File needs to be ..")
    6.         Unload Me
    7.     End If
    8. End Sub

    but that doesnt work.

  2. #2
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: FileExists:

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4. Dim f As String
    5. f = Dir("*.vbp", vbNormal)
    6. If f <> "" Then Beep
    7. End Sub

    This beeps as its in my VB98 folder. Supply your folder name, and file name to check on the file existance.

  3. #3

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: FileExists:

    where do i change the filename? i want it to check if a dir exists

  4. #4
    Addicted Member akki's Avatar
    Join Date
    Jun 2003
    Location
    Jungle
    Posts
    220

    Re: FileExists:

    VB Code:
    1. Dim fso As New FileSystemObject
    2.     If fso.FolderExists("C:\xyz") Then
    3.         'Yes
    4.     Else
    5.         'No
    6.     End If

    Quote Originally Posted by |2eM!x
    Just wondering, how do you check if a directory exists? i thought it was like
    VB Code:
    1. Private Sub Form_Load()
    2.     If FileExists(App.Path & "\yay.dir") Then
    3.         Print vbNullString
    4.     Else
    5.         MsgBox ("File needs to be ..")
    6.         Unload Me
    7.     End If
    8. End Sub

    but that doesnt work.
    akki

  5. #5
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: FileExists:

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4. Dim f As String
    5. f = Dir("c:\windows", vbDirectory)
    6. If f <> "" Then Beep
    7.  
    8. End Sub

    as you type DIR("", you are prompted with intellisence prompts for the choices you can use. there are about 7 of them
    you can use + to combine them

  6. #6

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: FileExists:

    "user-defined type not defined"

    edit**
    yay thanks dg, youve saved my night

  7. #7
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: FileExists:

    need a reference to file scripting object

  8. #8
    Addicted Member akki's Avatar
    Join Date
    Jun 2003
    Location
    Jungle
    Posts
    220

    Re: FileExists:

    you need to add Microsoft Scripting Runtime for that.

    any way, you already got a simple one your hands.

    Quote Originally Posted by |2eM!x
    "user-defined type not defined"

    edit**
    yay thanks dg, youve saved my night
    akki

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