Share your advanced PureBasic knowledge/code with the community.
jamirokwai
Enthusiast
Posts: 798 Joined: Tue May 20, 2008 2:12 am
Location: Cologne, Germany
Contact:
Post
by jamirokwai » Sun Apr 15, 2012 9:18 am
Hi there,
as CreateDirectory does not create a folder tree, I hacked a small function to do this...
Should be self explanatory.
Code: Select all
Procedure Create_FolderTree(dest$)
If Right(dest$,1) <> "/" : dest$ + "/" : EndIf
If FileSize(dest$) = -1
Temp$ = ""
For i = 1 To CountString(dest$,"/")
temp$ + StringField(dest$,i,"/") + "/"
If FileSize(Temp$) = -1
CreateDirectory(Temp$)
EndIf
Next i
EndIf
EndProcedure
Last edited by
jamirokwai on Tue Apr 17, 2012 11:17 am, edited 1 time in total.
Regards,
JamiroKwai
Guimauve
Enthusiast
Posts: 742 Joined: Wed Oct 22, 2003 2:51 am
Location: Canada
Post
by Guimauve » Mon Apr 16, 2012 4:13 am
Hello,
This a cross-platform solution :
Code: Select all
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Project name : BuiltPathDirectory
; File Name : BuiltPathDirectory.pb
; File version: 1.1.0
; Programming : OK
; Programmed by : Guimauve
; Date : 29-04-2008
; Last Update : 15-04-2012
; PureBasic code : 4.60
; Platform : Windows, Linux, MacOS X
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Procedure.b BuiltPathDirectory(Path.s)
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Windows
PathSep.s = "\"
CompilerCase #PB_OS_Linux
PathSep.s = "/"
CompilerCase #PB_OS_MacOS
PathSep.s = "/"
CompilerEndSelect
DirectoryQty = CountString(Path, PathSep) + 1
For Index = 1 To DirectoryQty
Directory.s = Directory + StringField(Path, Index, PathSep) + PathSep
If FileSize(Directory) = -1
CreateDirectory(Directory)
EndIf
Next
If FileSize(Directory) = -2
Success.b = #True
Else
Success = #False
EndIf
ProcedureReturn Success
EndProcedure
; <<<<<<<<<<<<<<<<<<<<<<<
; <<<<< END OF FILE <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<
Best regards
Guimauve
USCode
Addict
Posts: 924 Joined: Wed Mar 24, 2004 11:04 pm
Location: Seattle
Post
by USCode » Mon Apr 16, 2012 5:42 am
Doesn't Windows accept both / and \ as path delimiters ?
HeX0R
Addict
Posts: 1205 Joined: Mon Sep 20, 2004 7:12 am
Location: Hell
Post
by HeX0R » Mon Apr 16, 2012 8:19 pm
jamirokwai wrote: Hi there,
Should be self explanatory.
If this was your goal, you shouldn't use german variablenames. (And where does
zielort$ come from?)
jamirokwai
Enthusiast
Posts: 798 Joined: Tue May 20, 2008 2:12 am
Location: Cologne, Germany
Contact:
Post
by jamirokwai » Tue Apr 17, 2012 11:18 am
HeX0R wrote: jamirokwai wrote: Hi there,
Should be self explanatory.
If this was your goal, you shouldn't use german variablenames. (And where does
zielort$ come from?)
Oh, yeah
For your convenience, changed to dest$ ...
And thanks for the hint, regarding the error with zielort$ ...
Regards,
JamiroKwai