Click to See Complete Forum and Search --> : How to retrieve the current Directory and create a directory in it using VB code


Ali Habib
March 27th, 2001, 07:11 AM
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.

shree
March 27th, 2001, 08:21 AM
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

coolbiz
March 27th, 2001, 08:25 AM
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