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
CreateDirectory() with flag #PB_FileSystem_Recursive
CreateDirectory() with flag #PB_FileSystem_Recursive
PB 5.70 LTS (x64) - Debian Testing, Gnome 3.30.2
Re: CreateDirectory() with flag #PB_FileSystem_Recursive
+1uwekel wrote:...a flag for the CreateDirectory() function for creating all folders for the given path if the #PB_FileSystem_Recursive flag would be set.
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")
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel
-
- Always Here
- Posts: 6425
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: CreateDirectory() with flag #PB_FileSystem_Recursive
+1
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
Re: CreateDirectory() with flag #PB_FileSystem_Recursive
that would be quite helpful -> +1
Thanks in advance & Greetings ... Peter
Thanks in advance & Greetings ... Peter
Hygge
Re: CreateDirectory() with flag #PB_FileSystem_Recursive
There is also a native Win32 command which does this:
https://msdn.microsoft.com/en-us/librar ... s.85).aspx
https://msdn.microsoft.com/en-us/librar ... s.85).aspx
Re: CreateDirectory() with flag #PB_FileSystem_Recursive
Mistrel, MakeSureDirectoryPathExists_() doesn't work with Unicode, which PureBasic now is. However, we can use SHCreateDirectory_() instead:
Or here's some short cross-platform code that I used to use:
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.
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