Create Nested Folders In One Call

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:1stDir2ndDir3rdDir4thDir 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, "")	Loop	Exit FunctionFailed:	MkDirs = FalseEnd 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.

Share the Post:
data observability

Data Observability Explained

Data is the lifeblood of any successful business, as it is the driving force behind critical decision-making, insight generation, and strategic development. However, due to its intricate nature, ensuring the

Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved