esthera
04-30-2007, 10: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?
<%
mynewdirectory="d:\db\2007\04\28\10"
checkdirectory(mynewdirectory)
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
Else
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
Next
response.write tmt
if tmt<>"" then
If Not objFSO.FolderExists(tmtT) then
objFSO.CreateFolder(tmt)
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
Next
'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
%>
it is not working -- can someone help me debug?
<%
mynewdirectory="d:\db\2007\04\28\10"
checkdirectory(mynewdirectory)
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
Else
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
Next
response.write tmt
if tmt<>"" then
If Not objFSO.FolderExists(tmtT) then
objFSO.CreateFolder(tmt)
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
Next
'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
%>