View Full Version : debug code -- create directory

04-30-2007, 11:24 AM
the code below should check if a directory path exists and if not create it
it is not working -- can someone help me debug?


Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
If objFSO.FolderExists(mynewdirectory) then response.write mynewdirectory & " was created"
Function CheckDirectory(dirPath)

Set objFSO = Server.CreateObject("Scripting.FileSystemObject")

If objFSO.FolderExists(dirpath) then
CheckDirectory = True

CheckDirectory = False

'Temp variables created.
Dim tmpS, prefix, tmpT

Dim tmpI , tmpJ
'The first 3 characters of the path are
' cut off and the rest of the path is spli
' t into an array.
tmpS = dirPath
prefix = Left(tmpS, 3)
tmpS = Mid(tmpS, 4)
tmpA = Split(tmpS, "\")
'Loop of the array where starting from t
' he first folder in the path the director
' ies are tested.
'If the directory does not exist it is c
' reated if it already exists the loop con
' tinues.
'This will verify that the entire direct
' ory structure is created in the proper o
' rder.

For tmpI = 0 To UBound(tmpA)
tmpT = prefix

For tmpJ = 0 To tmpI
tmpT = tmpT & tmpA(tmpJ) & "\"

' If tmpJ > 100 Then Exit Function

response.write tmt
if tmt<>"" then
If Not objFSO.FolderExists(tmtT) then

End If
end if
' If Dir(tmpT, vbDirectory) = "" Then MkDir (tmpT)
'In case of unknows the loop will stop a
' fter 100 times.
'This should a safe count as a directory
' structure should never reach this length
' .
If tmpI > 100 Then Exit Function

'Directory is checked again.
'This is in case user did not have write
' permissions on any part of the directory
' creation process.
If objfso.folderexists(tmt) Then CheckDirectory = True
End If

End Function


04-30-2007, 03:26 PM
Well, I see a missing End If right off the bat.

If objFSO.FolderExists(mynewdirectory) then
response.write mynewdirectory & " was created"
End If

Function CheckDirectory(dirPath)