Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Expertise: Beginner
Nov 18, 1999



Application Security Testing: An Integral Part of DevOps

Create Nested Folders In One Call

Suppose you need to create a tree of directories, all at once, in code. For example, you could create the tree C:\1stDir\2ndDir\3rdDir\4thDir with one call simply by feeding that path, as a string, into this procedure:
Public Function MkDirs(ByVal PathIn As String) _
	As Boolean
	Dim nPos As Long
	MkDirs = True  'assume success
	If Right$(PathIn, 1) <>"\" Then PathIn = _
		PathIn + "\"
	nPos = InStr(1, PathIn, "\")
	Do While nPos > 0
		If Dir$(Left$(PathIn, nPos), _
			vbDirectory) = "" Then
			On Error GoTo Failed
				MkDir Left$(PathIn, nPos)
			On Error GoTo 0
		End If
		nPos = InStr(nPos + 1, PathIn, "\")
	Exit Function
	MkDirs = False
End Function 
If any part of the path already exists, the routine creates only the new part. This routine works on strings representing local and mapped drives-those with a letter, colon, and backslash at the beginning. If the drive designation is left out, the directories are created starting at the default directory on the current drive.
Frederick Rothstein
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date