Page 1 of 1

Create Folder-Tree

Posted: Sun Apr 15, 2012 9:18 am
by jamirokwai
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

Re: Create Folder-Tree

Posted: Mon Apr 16, 2012 4:13 am
by Guimauve
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

Re: Create Folder-Tree

Posted: Mon Apr 16, 2012 5:42 am
by USCode
Doesn't Windows accept both / and \ as path delimiters ?

Re: Create Folder-Tree

Posted: Mon Apr 16, 2012 8:19 pm
by HeX0R
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?)

Re: Create Folder-Tree

Posted: Tue Apr 17, 2012 11:18 am
by jamirokwai
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$ ...