Tip

Sub-Directories Check For Existance And Add If It Doesn't Already Exist

This is a neat little function that checks to see if a declared subdirectory
exists and if is doesn't then it creates it. It assumes that the parent
directory exists, so if in doubt then call the function several times starting
at the root.

This is a useful function if, like me, you want to control the detaching of
documents so that they are placed using script in the same sub directory on all
user's machines
To call the function:

CheckForCreateDirectory("c:\notes\data\attachments")


The Function itself:

Function CheckForCreateDirectory(DirPath As String)
'This function checks for a subdirectory given the parent, and if it doesn't
exist it creates it

'Extract the different elements of the full path
DirName=DirPath
Continue=False
Do While continue=False
If Instr(DirName,"\") Then
DirName=Right(DirName,Len(DirName)-Instr(DirName,"\"))
Else
Continue=True
End If
Loop
ParentDirPath=Left(DirPath,Len(DirPath)-Len(DirName))

'Check for directory and add if it doesn't exits
CheckDir = Dir$(ParentDirPath,16)
CheckDirFlag=False
Do While CheckDir <> ""
If Ucase(CheckDir) = Ucase(DirName) Then
CheckDirFlag = True
End If
CheckDir = Dir$()
Loop
If CheckDirFlag=False Then
Mkdir DirPath
End If
End Function

This was first published in November 2000

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.