Subject: Well I solved your code issue.
Ok the issue is not related to MKDIR. Appears to be related to DIR$.
I had some spare time, so here is what I did.
-
Cleaned up your code to a much smaller sample.
-
Ran it and deleted the directories from the command prompt. Worked fine.
-
Ran it twice, as the logic is different the second time. Attempting to delete the directories the second last in the tree could not be removed (eg. “c:\a\b\c\d” directory c could not be removed).
-
Tested it a few times on different directory structures and confirmed it is related to the second last directory.
-
Moved the DIR$ out of the IF conditional statements to determine if they are connected. Could still reproduce the issue.
-
Now that I know the issue is related to DIR$ I checked for existing SPRs. I found JDYU6679FJ. this is a crash issue (which turned out not to be an issue). Not directly related to this issue, but mentioned that if DIR$ is called with parameters the CAPI code is put into a loop holding the directory. It is only returned if an error condition happens.
-
To test this I added a line at the end of the code to do DIR$(“C:\temp”). As it has no parameters it should break the loop. Testing with this I was no longer able to recreate the issue.
Created SPR SODY85SM84 which details this issue so development can investigate further. I will do up a tech note later on it.
Here is the sample code if your interested. Hope all this helps.
Option Public
Option Declare
Const ATTR_DIRECTORY = 16
Sub Initialize()
Const testDirectory = "c:\temp\simon\11\22\33\" ' requires \ at the end of the string or will fail.
createDirs(testDirectory)
End Sub
Private Function createDirs(path As String) As Boolean
On Error GoTo CP_DOH
Dim drive As String
Dim orgDir As String
Dim part As String
Dim rest As String
Dim ndx As Long
Dim first As Boolean
Dim dirCheck As string
part=“”
drive=“”
createDirs=True
first=True
orgDir=CurDir$
rest=path
ndx=InStr(rest, "")
Print |Creating dirs for '|+path+|"|
While(ndx>0)
If(part="") Then
part=Left$(rest, ndx-1)
Else
part=part+"\"+Left$(rest, ndx-1)
End If
rest=Mid$(rest, ndx+1)
If(first And InStr(part, ":")>0) Then
Print |- Set drive |+part
drive=CurDrive$
ChDrive part
first=False
Else
dirCheck = Dir$(part, ATTR_DIRECTORY)
Print "Dir$ = " + dirCheck
If(dirCheck = "" ) Then
Print |- Mkdir |+part
MkDir(part)
Else
Print |- Reuse |+part
End If
End If
ndx=InStr(rest, "\")
Wend
’ This line will stop the locking from occurring.
’ Appears to be related to SPR JDYU6679FJ
’ ***********************************************
’ dirCheck = Dir$(“c:\temp”) ’ Force without parameters
CP_DONE:
If(drive<>“”) Then
ChDrive drive
End If
’ return to original directory.
ChDir orgDir
Exit Function
CP_DOH:
createDirs=False
print | line | & Erl & | of createDirs: “|+Error$+|”|
Resume CP_DONE
End Function