GetUserDirectoryEx(...)

Share your advanced PureBasic knowledge/code with the community.
User avatar
mk-soft
Always Here
Always Here
Posts: 6249
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

GetUserDirectoryEx(...)

Post by mk-soft »

Small snipped :wink:

Code: Select all

;-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
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: GetUserDirectoryEx(...)

Post by Kwai chang caine »

Thanks 8)
ImageThe happiness is a road...
Not a destination
Post Reply