Thanks for posting Bisonte! I was hoping the thread title might draw in a cross platform solution. Not that I need one (I don't) but just to help complete the full path concept within this thread for all to see.Bisonte wrote: Wed Mar 11, 2026 11:33 pm in a crossplatform way from TS-Soft (German Forum) modified by me a little... :
Code: Select all
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
Create Full Path Procedure
-
Randy Walker
- Addict

- Posts: 1281
- Joined: Sun Jul 25, 2004 4:21 pm
- Location: USoA
- Contact:
Re: Create Full Path Procedure
- - - - - - - - - - - - - - - -
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.
Re: Create Full Path Procedure
Code: Select all
Procedure.s MakePath(FullPath$)
Protected Path$, cs, i
FullPath$ = RTrim(FullPath$, #PS$)
cs = CountString(FullPath$, #PS$) + 1
For i = 1 To cs
Path$ + StringField(FullPath$, i, #PS$) + #PS$
If FileSize(Path$) <> -2 And Not CreateDirectory(Path$)
ProcedureReturn Path$ ; Error Folder
EndIf
Next
EndProcedure ; returns "" if no error occurredRe: Create Full Path Procedure
This doesn't work with the latest PureBasic because it's ANSI only (not Unicode). That's why I use SHCreateDirectory_() instead.
Code: Select all
MakeSureDirectoryPathExists_("d:\1\2\3\") ; No dirs created.Re: Create Full Path Procedure
If you like recursion, or at least don't mind it, then you can also do it this way:
Code: Select all
Procedure EnsureDirectory(Directory$) ; BOOL .. returns TRUE if directory exists, (already or created)
If Directory$ : Debug #PB_Compiler_Procedure+"("+Directory$+")", 9
;> here it doesn't matter if trailing #PS$ or not
If FileSize(Directory$) = #PB_FileSize_Directory
ProcedureReturn #True ; directory exists (already)
Else
If EnsureDirectory(GetPathPart(RTrim(Directory$, #PS$))) ; recursive call with parent directory
;> CreateDirectory() .. returns nonzero if the operation was successful or zero if it failed.
ProcedureReturn CreateDirectory(Directory$)
EndIf
EndIf
EndIf
ProcedureReturn #False ; clean code => defined return value
EndProcedure
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).
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).