Page 1 of 1
CreateDirectory() with flag #PB_FileSystem_Recursive
Posted: Fri Apr 13, 2018 3:36 pm
by uwekel
Hi,
it would be nice to have a flag for the CreateDirectory() function for creating all folders for the given path if the #PB_FileSystem_Recursive flag would be set.
Thx, Uwe
Re: CreateDirectory() with flag #PB_FileSystem_Recursive
Posted: Fri Apr 13, 2018 6:27 pm
by TI-994A
uwekel wrote:...a flag for the CreateDirectory() function for creating all folders for the given path if the #PB_FileSystem_Recursive flag would be set.
+1
In the meantime, here's a routine that does just that:
Code: Select all
Procedure CreateDirectories(fullPath.s)
fullPath = ReplaceString(fullPath, "\", "/")
If Right(fullPath, 1) <> "/"
fullPath + "/"
EndIf
depth = CountString(fullPath, "/")
Dim folder.s(depth)
For i = 1 To depth
folder(i) = StringField(fullPath, i, "/")
Next
For i = 1 To depth
If i = 1
currentFolder$ = folder(i)
If CountString(folder(i), ":")
currentFolder$ + "/" + folder(i + 1)
i + 1
EndIf
Else
currentFolder$ + "/" + folder(i)
EndIf
If FileSize(currentFolder$) <> -2
If CreateDirectory(currentFolder$) = 0
Break
Else
Debug currentFolder$ + " created!"
EndIf
EndIf
Next
EndProcedure
CreateDirectories("d:\Fantaisie\PureBasic\64bit\examples\advanced\graphics\bitmaps")
Re: CreateDirectory() with flag #PB_FileSystem_Recursive
Posted: Fri Apr 13, 2018 9:10 pm
by davido
+1
Re: CreateDirectory() with flag #PB_FileSystem_Recursive
Posted: Fri Apr 13, 2018 9:20 pm
by IdeasVacuum
+1
Re: CreateDirectory() with flag #PB_FileSystem_Recursive
Posted: Fri Apr 13, 2018 10:05 pm
by Kiffi
that would be quite helpful -> +1
Thanks in advance & Greetings ... Peter
Re: CreateDirectory() with flag #PB_FileSystem_Recursive
Posted: Fri Apr 13, 2018 11:02 pm
by Mistrel
There is also a native Win32 command which does this:
https://msdn.microsoft.com/en-us/librar ... s.85).aspx
Re: CreateDirectory() with flag #PB_FileSystem_Recursive
Posted: Sat Apr 14, 2018 1:49 am
by Dude
Mistrel, MakeSureDirectoryPathExists_() doesn't work with Unicode, which PureBasic now is. However, we can use SHCreateDirectory_() instead:
Code: Select all
dirtree$="d:\aa\bb\cc\"
Debug MakeSureDirectoryPathExists_(dirtree$) ; Shows 1, but didn't work.
Debug SHCreateDirectory_(0,dirtree$) ; Shows 0, but did create the tree.
Or here's some short cross-platform code that I used to use:
Code: Select all
Procedure CreateDirectoryTree(dir$)
ok=1
If Right(dir$,1)<>"\" : dir$+"\" : EndIf
If FileSize(dir$)<>-2
For a=1 To CountString(dir$,"\")
tmp$+StringField(dir$,a,"\")+"\"
If FileSize(tmp$)=-1
If CreateDirectory(tmp$)=0
ok=0
Break
EndIf
EndIf
Next
EndIf
ProcedureReturn ok
EndProcedure
Re: CreateDirectory() with flag #PB_FileSystem_Recursive
Posted: Mon Apr 16, 2018 3:15 pm
by RSBasic
+1
Re: CreateDirectory() with flag #PB_FileSystem_Recursive
Posted: Mon Apr 16, 2018 4:53 pm
by Cyllceaux
+1