CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2000
    Posts
    57

    How to retrieve the current Directory and create a directory in it using VB code

    I am using common dialog control to get the file name, user wants to save. Also I have a text box in which the user can enter the filename manually. Incase the user enters the filename to be saved manually, how can I validate the filename and Directory using VB. Secondly if the directory path specified by the user doesnot exist , how can i create the directory structure through VB code. Finally how can I retrieve the curr Directory path, incase user only enter the filename.
    I would greatly appreciate any help in this regard. Thanks

    Ali.


  2. #2
    Join Date
    Mar 1999
    Location
    Nepal
    Posts
    540

    Re: How to retrieve the current Directory and create a directory in it using VB code

    I'll answer last first.

    The current directory is given by CurDir. So, you can use

    FullPath = CurDir & "\filename.ext"

    You use the following to see if a directory exists.

    on error resume next
    Err.Clear
    If (GetAttr(MyPath) And vbDirectory) = vbDirectory then
    MsgBox MyName
    'Do your work here
    End If
    If Err.Number then MsgBox "Directory doesn't exist"



    Though this is a bit crude, nothing else came to my mind. You can use a similar method to validate if hte file is there.

    To separate the different fields in a full file path, use

    Dim Parts
    Parts = Split(FullPath, "\")



    To change directory, use

    ChDir

    and to create a new one,

    MkDir



  3. #3
    Join Date
    Feb 2001
    Location
    Stamford CT USA
    Posts
    2,167

    Re: How to retrieve the current Directory and create a directory in it using VB code

    If you're using Microsoft Common Dialog Control, then you can set the .Flag properties to ensure that the PATH MUST EXIST before the user can click on OK button.

    In any case, to manually check for the exsistent of a directory or file you can use Dir() function.

    To create directory, you can use Mkdir() function and to retrieve the current directory, you can use CurDir() function.

    -Cool Bizs

    Good Luck,
    -Cool Bizs

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

Featured