DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Checking the existence of path...???

  1. #1
    Ali Imran Guest

    Checking the existence of path...???


    How could I check if the Path (Directory, Folder) Exist or not?

    How could I do it in VB?


  2. #2
    Jerry Nesbett Guest

    Re: Checking the existence of path...???


    One way I did it was as follows:
    I wanted to find out if there was a directory named "passtext" as a
    subdirectory of the current directory and if there wasn't I wanted
    to create it, so I coded the following:

    Do While DirName <> "" and DirName<>"passtext"
    DirName = Dir
    Loop
    If DirName = "" Then
    MkDir passdir
    end if

    The place I found this information is by looking up the
    Dir function in the Help file of VB 6.

    "Ali Imran" <aimran@saudionline.com.sa> wrote:
    >
    >How could I check if the Path (Directory, Folder) Exist or not?
    >
    >How could I do it in VB?
    >



  3. #3
    Joe \Nuke Me Xemu\ Foster Guest

    Re: Checking the existence of path...???

    "Ali Imran" <aimran@saudionline.com.sa> wrote in message <news:3d75c350$1@10.1.10.29>...

    > How could I check if the Path (Directory, Folder) Exist or not?
    >
    > How could I do it in VB?


    I'd better jump in here before yet another idiot advocates using
    the FileSystemAbomination or, even worse, DIR() or Len(Dir$())!

    Public Function DriveExists(ByVal DriveSpec As String) As Boolean
    On Error Resume Next
    DriveExists = Len(CurDir$(DriveSpec)) > 0
    End Function

    Public Function FolderExists(ByVal FolderSpec As String) As Boolean
    On Error Resume Next
    FolderExists = (GetAttr(FolderSpec) And vbDirectory) = vbDirectory
    End Function

    FileExists may be trickier, since Lose2K and XP introduce some new
    oddities, such as "reparse points", but this should do for now:

    Public Function FileExists(ByVal FileSpec As String) As Boolean
    On Error Resume Next
    FileExists = (GetAttr(FileSpec) And vbDirectory) = 0
    End Function

    Keep in mind that nearly anything could "exist" without necessarily
    being accessible to your app. Files and directories can be deleted
    right after one of the above functions returns True, but before you
    can actually do anything with them, so you'll have to trap any errors
    anyway. This means writing (and maintaining!) the same logic *twice*,
    which all too often turns out to be a train-wreck waiting to happen...

    --
    Joe Foster <mailto:jlfoster%40znet.com> Got Thetans? <http://www.xenu.net/>
    WARNING: I cannot be held responsible for the above They're coming to
    because my cats have apparently learned to type. take me away, ha ha!



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center