Seite 1 von 1

CreatePath - erstellt beliebig tiefe Verzeichnisebenen

Verfasst: 03.02.2017 17:37
von Sicro

Code: Alles auswählen

CompilerSelect #PB_Compiler_OS
  CompilerCase #PB_OS_Windows
    #Path_Slash$ = "\"
  CompilerDefault
    #Path_Slash$ = "/"
CompilerEndSelect

Procedure.i CreatePath(Path$)
  
  Protected CountOfDirectories, i
  Protected TempPath$
  
  Path$ = Trim(Path$, #Path_Slash$)
  
  CountOfDirectories = CountString(Path$, #Path_Slash$) + 1
  For i = 1 To CountOfDirectories
    CompilerIf #PB_Compiler_OS = #PB_OS_Windows
      If i = 1
        TempPath$ = StringField(Path$, i, #Path_Slash$)
        Continue
      EndIf
    CompilerEndIf
    TempPath$ + #Path_Slash$ + StringField(Path$, i, #Path_Slash$)
    If FileSize(TempPath$) <> -2 And Not CreateDirectory(TempPath$)
      ProcedureReturn #False
    EndIf
  Next
  
  ProcedureReturn #True
EndProcedure

;Debug CreatePath("/home/username/myproject/codes/gui")
;Debug CreatePath("C:\Dokumente und Einstellungen\Benutzername\Programmieren\Mein Projekt\GUI")
Der obige Code wird nicht mehr aktualisiert. Bitte schaue für den aktuellsten Code ins CodeArchiv:
https://github.com/SicroAtGIT/PureBasic ... iv-Rebirth
Pfad: FileSystem/CreatePath