Bill, I didn't mean to step on your (or anybody's) toes.
A preference is a just a preference, with its pros and cons.
I have nothing against FSO and it does its job just fine
when Windows Scripting Host is enabled. But some users disable it, because of virus threat, and the FSO is then just dead meat-CreateObject fails.
I reviewed the code and here is a function that checks and creates the entire chain from sctratch or just the subdirectories that do not exist. The function output is the number of subdirectories created within the chain.
Not passing a drive or \\sharename will result in creation of the chain in the current directory.
The code is 17 lines long (except declarations and comments)...
Function fCheckDirs(strDir As String) As Integer
'***************************************************
'Purpose: To check/create directories
'Input: Path upto the final directory
'Output: number of directories created
'May 19, 2003
'Tek-Tips thread705-550174
'Daniel Vlas
'***************************************************
Dim strDirectory As String
Dim strRoot As String
'C:\, D:\, \\ShareName\
Dim i As Integer
'detect root
If Left(strDir, 1) = "\" Then
'UNC, starts with \'----------------------------------------------------------
'Extract root of UNC path
strRoot = Right(strDir, Len(strDir) - 2)
If InStr(strRoot, "\"

> 0 Then
strRoot = "\\" & Left(strRoot, InStr(strRoot, "\"

)
End If
'---------------------------------------------------------
Else
'---------------------------------------------------------
'Just take the drive letter + :
strRoot = Left(strDir, 2)
'----------------------------------------------------------
End If
'-----------------------------------------------------------
'Remove the root from the path-it should NOT be created!
strDirectory = Right(strDir, Len(strDir) - Len(strRoot))
'-----------------------------------------------------------
'-----------------------------------------------------------
'Start looping throug the characters in the path
For i = 1 To Len(strDirectory)
'-----------------------------------------------------------
'--------------------------------------------------------------------
'Subdirectory found or final path
If Mid(strDirectory, i + 1, 1) = "\" Or i = Len(strDirectory) Then
'----------------------------------------------------------
'-------------------------------------------------------
'If subdirectory does not exist, create it and increment function output
If Dir(strRoot & Left(strDirectory, i), vbDirectory) = "" Then
MkDir (strRoot & Left(strDirectory, i))
fCheckDirs = fCheckDirs + 1
'------------------------------------------------------
End If
End If
'-----------------------------
'Move to next character
Next
'-----------------------------
End Function
Good luck
![[pipe] [pipe] [pipe]](/data/assets/smilies/pipe.gif)
Daniel Vlas
Systems Consultant