You'll have to uncomment the CreateDirectory line for it to actually work, but run as is in Debugger to see how it would work in action. Of course, IF the drive exists it will fail to create the root directory. To be expected:
Procedure Makepath(Sample$)
Sample$ = Trim(Sample$, "\")
Path$ = ""
For D = 1 To CountString(Sample$, "\") + 1
Path$ + StringField(Sample$, D, "\") + "\"
If FileSize(Path$) = -1
Debug Path$
; CreateDirectory(Path$)
Else
Debug Path$+" already exists"
EndIf
Next D
EndProcedure
;Examples with and without trailing \
Makepath("D:\Eat\At\Joes\Bar\And\Grill\")
Delay(3000)
Makepath("D:\Eat\At\Joes\Bar\And\Grill")
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
Nothing is faster, more stable, or easier to maintain than code that doesn’t exist.
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
Nothing is faster, more stable, or easier to maintain than code that doesn’t exist.
I'm, guessing change backslash to forward slash for Linux or MAC in my procedure to get it to work there. Cannot test here.
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
Nothing is faster, more stable, or easier to maintain than code that doesn’t exist.
Randy Walker wrote: Tue Mar 10, 2026 9:08 am
I'm, guessing change backslash to forward slash for Linux or MAC in my procedure to get it to work there. Cannot test here.
Fun Fact: It's on the Deprecated APi Section since more than 10 years now.
SHCreateDirectory is available for use in the operating systems specified in the Requirements section. It may be altered or unavailable in subsequent versions.
Just because it worked doesn't mean it works. PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
Not on Mac: you cannot create a dir if there's a file with the same name (at least not on Finder… don't wanna risk to try with PB and nuke my filesystem )
Fun Fact: It's on the Deprecated APi Section since more than 10 years now.
SHCreateDirectory is available for use in the operating systems specified in the Requirements section. It may be altered or unavailable in subsequent versions.
Yes, thats a good one, too.
And reading the comments section is even more fun.
Remarks
Each directory specified is created, if it does not already exist. If only some of the directories are created, the function will return FALSE.
This function does not support Unicode strings. To specify a Unicode path, use the SHCreateDirectoryEx function.
All DbgHelp functions, such as this one, are single threaded. Therefore, calls from more than one thread to this function will likely result in unexpected behavior or memory corruption. To avoid this, you must synchronize all concurrent calls from more than one thread to this function.
Just because it worked doesn't mean it works. PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
Axolotl wrote: Wed Mar 11, 2026 5:04 pm
Yes, thats a good one, too.
And reading the comments section is even more fun.
Remarks
Each directory specified is created, if it does not already exist. If only some of the directories are created, the function will return FALSE.
This function does not support Unicode strings. To specify a Unicode path, use the SHCreateDirectoryEx function.
All DbgHelp functions, such as this one, are single threaded. Therefore, calls from more than one thread to this function will likely result in unexpected behavior or memory corruption. To avoid this, you must synchronize all concurrent calls from more than one thread to this function.
I don't know or understand Unicode Well enough to write code that supports it and as far as I'm concerned, don't have any use for it. Feel free to provide what you would consider to be a superior Procedure. I wont be offended. If you're comfortable using the SHCreate thing, that's fine too. Seems if the end user of your code doesn't have the Dbghelp.lib then your code will fail, Also from the official MS website: "This function is available through Windows XP Service Pack 2 (SP2) and Windows Server 2003. It might be altered or unavailable in subsequent versions of Windows."
So bottom line seems to be: Your SHCreate thing may not be the best possible path. No pun intended.
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
Nothing is faster, more stable, or easier to maintain than code that doesn’t exist.
Procedure.i CreateDirectoryEx(DirectoryName.s, FileAttribute = #PB_Default) ; Erstellt Verzeichnis, inklusive Übergeordnete
Protected i, c, tmp.s
If Right(DirectoryName, 1) = #PS$
DirectoryName = Left(DirectoryName, Len(DirectoryName) -1)
EndIf
c = CountString(DirectoryName, #PS$) + 1
For i = 1 To c
tmp + StringField(DirectoryName, i, #PS$)
If FileSize(tmp) <> -2
CreateDirectory(tmp)
EndIf
tmp + #PS$
Next
If FileAttribute <> #PB_Default
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
SetFileAttributes_(DirectoryName, FileAttribute)
CompilerElse
SetFileAttributes(DirectoryName, FileAttribute)
CompilerEndIf
EndIf
If FileSize(DirectoryName) = -2
ProcedureReturn #True
EndIf
EndProcedure
PureBasic 6.21 (Windows x64) | Windows 11 Pro | AsRock B850 Steel Legend Wifi | R7 9800x3D | 64GB RAM | RTX 5080 | ThermaltakeView 270 TG ARGB | build by vannicom
English is not my native language... (I often use DeepL.)