GetUserDirectoryEx(...)

Hier könnt Ihr gute, von Euch geschriebene Codes posten. Sie müssen auf jeden Fall funktionieren und sollten möglichst effizient, elegant und beispielhaft oder einfach nur cool sein.
Benutzeravatar
mk-soft
Beiträge: 3695
Registriert: 24.11.2004 13:12
Wohnort: Germany

GetUserDirectoryEx(...)

Beitrag von mk-soft »

Kleiner Progammauszug :wink:

Code: Alles auswählen

;-TOP

; Comment: GetUserDirectoryEx
; Author : mk-soft
; Version: v1.01
; Created: 013.09.2018
; Updated: 10.09.2018
; Link   :

CompilerIf #PB_Compiler_OS = #PB_OS_Windows
  #PS$ = "\"
CompilerElse
  #PS$ = "/"
CompilerEndIf

Procedure.s GetUserDirectoryEx(DirectoryType, Path.s = "")
  Protected result.s, dir.s, part.s, cnt
  dir = GetUserDirectory(DirectoryType)
  If Right(dir, 1) <> #PS$
    dir + #PS$
  EndIf
  result = dir + path
  If Not FileSize(result) = -2
    result = dir
    Repeat
      cnt + 1
      part = StringField(path, cnt, #PS$)
      If Not Bool(part)
        Break
      EndIf
      result + part + #PS$
      If Not FileSize(result) = -2
        If Not CreateDirectory(result)
          Debug "Error: GetUserDirectoryEx(" + result + ")"
          ProcedureReturn ""
        EndIf
      EndIf
    ForEver
  EndIf
  If Right(result, 1) <> #PS$
    result + #PS$
  EndIf
  ProcedureReturn result
EndProcedure

CompilerIf #PB_Compiler_IsMainFile
  Define dir.s = GetUserDirectoryEx(#PB_Directory_ProgramData, "purebasic")
  ;Define dir.s = GetUserDirectoryEx(#PB_Directory_ProgramData, "myprogram\v1.01\data")
  
  If OpenWindow(0, 0, 0, 400, 200, "ExplorerListGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    ExplorerListGadget(0, 10, 10, 380, 180, dir, #PB_Explorer_MultiSelect)
    Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
  EndIf
CompilerEndIf
Alles ist möglich, fragt sich nur wie...
Projekte ThreadToGUI / EventDesigner V3 / OOP-BaseClass-Modul
Downloads auf MyWebspace / OneDrive