Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
Thread: debug code -- create directory
04-30-2007, 10:24 AM #1
- Join Date
- May 2004
- Thanked 0 Times in 0 Posts
debug code -- create directory
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 %>
04-30-2007, 02:26 PM #2
- Join Date
- Jun 2005
- Near Chicago, IL, USA
- Thanked 32 Times in 31 Posts
Well, I see a missing End If right off the bat.
If objFSO.FolderExists(mynewdirectory) then
response.write mynewdirectory & " was created"
If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
Bored? Visit http://www.kaelisspace.com/