Results 1 to 7 of 7

Thread: Dir Function

  1. #1

    Thread Starter
    Hyperactive Member Pozzi's Avatar
    Join Date
    Feb 2001
    Location
    The Stones!
    Posts
    507
    Does anyone else find that the Dir Function doesn't fully work?

    Even tried the example in MSDN Library and that doesn't work?

    It works fine for a file on the root, but nothing is returned once I branch off the root.

    I'm using Win 2000, VB6 Pro (SP4)

  2. #2
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Works for me...
    Code:
    'check to see if a folder or directory does
    
    Private Sub Command1_Click()
    If Dir("C:\MyFolder\MySub", vbDirectory) <> "" Then
        MsgBox "Folder exists"
    Else
        MsgBox "Folder does not exist"
    End If
    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  3. #3

    Thread Starter
    Hyperactive Member Pozzi's Avatar
    Join Date
    Feb 2001
    Location
    The Stones!
    Posts
    507

    Question File

    Thanks,

    Yeah that worked, how about when you wnat to confirm a file exists?

    Dir("C:\Folder\MyFile.txt) ??

    Regards,

  4. #4
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Code:
    ...could be any of the the two and using Dir$ makes it 
    'faster as per the string conversion factor 
    
    1> If Dir$("C:\myFile.txt") then MsgBox "File Exists" 
    
    2> If len(Dir$("C:\myFile.txt")) > 0 then MsgBox "File Exists"
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  5. #5

    Thread Starter
    Hyperactive Member Pozzi's Avatar
    Join Date
    Feb 2001
    Location
    The Stones!
    Posts
    507

    Question

    The second is fine on the root.

    Do I need to change to the dirrect I want to search in first?

    The first gives me a Type Mismatch.

    Regards,

  6. #6
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Yes..if it is in any subDir it is not in the root.

    Ie.
    C:\myText.text is in C and can be found using

    If len(Dir$("C:\myFile.txt")) > 0 then MsgBox "File Exists"

    C:\my Documents\myfile.txt is not in the root of C
    and can only be found using the dir/subdir


    If len(Dir$("C:\my Documents\myFile.txt")) > 0 then MsgBox "File Exists"
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  7. #7

    Thread Starter
    Hyperactive Member Pozzi's Avatar
    Join Date
    Feb 2001
    Location
    The Stones!
    Posts
    507

    Question

    Works fine for the root but not when I branch off it?

    Can't understand it?

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