Results 1 to 8 of 8

Thread: quick dir question

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2000
    Posts
    344

    Unhappy

    Ok this code below works for a file
    If Dir$("\windows\car") <> "" Then
    msgbox "The File Car Exist"
    Else
    msgbox "The File Doesn't Exist"
    end if

    -------

    But i don't want to do it for a file i want to do it with a dir.

    If Dir$("\windows\") <> "" Then
    msgbox "The File Car Exist"
    Else
    msgbox "The File Doesn't Exist"
    end if

    If it exist, I get the right msg box...if it doesnt exist....i get a error that path doesnt exist.....y doesnt it skip to the else statement like the file does? And how can i fix it....thanks!
    -RaY
    VB .Net 2010 (Ultimate)

  2. #2
    Addicted Member
    Join Date
    May 2000
    Posts
    240

    Wink Try This!!

    Try using the "Not" Operator, hmm might help.

  3. #3
    Addicted Member
    Join Date
    Apr 2000
    Location
    Sheffield, England.
    Posts
    136
    Code:
    If Dir$("\windows\",vbDirectory) <> "" Then 
        MsgBox "The File Car Exist" 
    Else 
        MsgBox "The File Doesn't Exist" 
    End If
    ...might work. The Dir function has a second optional parameter.
    Visual Basic 6 Enterprise Edition + SP4

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    May 2000
    Posts
    344

    Angry Ok the real reply here hehe

    Nope tried both idea's didnt work...the first idea...it just reversed the error...and with the 2nd idea, same error.....keep it coming guys im sure its something small, but i can't just find it!
    -RaY
    VB .Net 2010 (Ultimate)

  5. #5
    Addicted Member
    Join Date
    Apr 2000
    Location
    Sheffield, England.
    Posts
    136
    Here's the exact code from my program which is tried and tested and DOES work in VB6.

    Code:
    If Dir(App.Path & "\Data\", vbDirectory) = "" Then MkDir App.Path & "\Data"
    That code checks to see if a directory exists, and if it doesn't it creates it.

    I just noticed you're using VB3 which might be the problem. Unfortunately VB6 is all I have, so I can't test it.

    If the vbDirectory constant isn't defined in VB3, then just substitute it for it's value (16). If THAT doesn't work then, I dunno.
    Visual Basic 6 Enterprise Edition + SP4

  6. #6
    Addicted Member
    Join Date
    Apr 2000
    Location
    Sheffield, England.
    Posts
    136

    Just had a thought...

    I wonder if, when you're referring to folders, you have to specify the FULL path - i.e. 'C:\WINDOWS\' instead of '\WINDOWS\'??
    Visual Basic 6 Enterprise Edition + SP4

  7. #7
    Junior Member
    Join Date
    Jun 2000
    Location
    Philippines
    Posts
    24

    You might want to try this:

    dim temp as string

    on error resume next

    temp = Dir("\windows\",vbDirectory)
    if err <> 0 then
    msgbox "Does not exist..."
    else
    msgbox "Exists...."
    end if

    or using File System Object:

    dim fso as variant

    set fso = createobject("FileSystemObjects")

    if fso.FolderExists("\windows\") then
    msgbox "Exists..."
    else
    msgbox "Does not exist...."
    end if


    hope this helps....

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    May 2000
    Posts
    344

    Thanks Zeee!

    thanks a lot guys but zee's worked great, u da man!
    -RaY
    VB .Net 2010 (Ultimate)

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