PureBasic Forum
http://forums.purebasic.com/english/

Get system folder location...
http://forums.purebasic.com/english/viewtopic.php?f=12&t=5152
Page 1 of 1

Author:  BackupUser [ Sun Feb 16, 2003 9:31 pm ]
Post subject: 

Restored from previous forum. Originally posted by Hi-Toro.

This will return the actual location of things like 'Program Files', 'My Documents', etc -- you can't assume the user has everything in C: these days! :)

Useful for writing installers (#CSIDL_PROGRAMS), 'Favorites' managers (#CSIDL_FAVORITES), etc...

Code:
; Get system folder location...

#CSIDL_INTERNET = $1
#CSIDL_PROGRAMS = $2
#CSIDL_CONTROLS = $3
#CSIDL_PRINTERS = $4
#CSIDL_PERSONAL = $5 ; Use this instead of CSIDL_MYDOCUMENTS. I don't know why! Ask Microsoft...
#CSIDL_FAVORITES = $6
#CSIDL_STARTUP = $7
#CSIDL_RECENT = $8
#CSIDL_SENDTO = $9
#CSIDL_BITBUCKET = $A
#CSIDL_STARTMENU = $B
#CSIDL_MYDOCUMENTS = $C
#CSIDL_MYMUSIC = $D
#CSIDL_MYVIDEO = $E
#CSIDL_DESKTOPDIRECTORY = $10
#CSIDL_DRIVES = $11
#CSIDL_NETWORK = $12
#CSIDL_NETHOOD = $13
#CSIDL_FONTS = $14
#CSIDL_TEMPLATES = $15
#CSIDL_COMMON_STARTMENU = $16
#CSIDL_COMMON_PROGRAMS = $17
#CSIDL_COMMON_STARTUP = $18
#CSIDL_COMMON_DESKTOPDIRECTORY = $19
#CSIDL_APPDATA = $1A
#CSIDL_PRINTHOOD = $1B
#CSIDL_LOCAL_APPDATA = $1C
#CSIDL_ALTSTARTUP = $1D
#CSIDL_COMMON_ALTSTARTUP = $1E
#CSIDL_COMMON_FAVORITES = $1F
#CSIDL_INTERNET_CACHE = $20
#CSIDL_COOKIES = $21
#CSIDL_HISTORY = $22
#CSIDL_COMMON_APPDATA = $23
#CSIDL_WINDOWS = $24
#CSIDL_SYSTEM = $25
#CSIDL_PROGRAM_FILES = $26
#CSIDL_MYPICTURES = $27
#CSIDL_PROFILE = $28
#CSIDL_SYSTEMX86 = $29
#CSIDL_PROGRAM_FILESX86 = $2A
#CSIDL_PROGRAM_FILES_COMMON = $2B
#CSIDL_PROGRAM_FILES_COMMONX86 = $2C
#CSIDL_COMMON_TEMPLATES = $2D
#CSIDL_COMMON_DOCUMENTS = $2E
#CSIDL_COMMON_ADMINTOOLS = $2F
#CSIDL_ADMINTOOLS = $30
#CSIDL_CONNECTIONS = $31
#CSIDL_COMMON_MUSIC = $35
#CSIDL_COMMON_PICTURES = $36
#CSIDL_COMMON_VIDEO = $37
#CSIDL_RESOURCES = $38
#CSIDL_RESOURCES_LOCALIZED = $39
#CSIDL_COMMON_OEM_LINKS = $3A
#CSIDL_CDBURN_AREA = $3B
#CSIDL_COMPUTERSNEARME = $3D
#CSIDL_FLAG_PER_USER_INIT = $800
#CSIDL_FLAG_NO_ALIAS = $1000
#CSIDL_FLAG_DONT_VERIFY = $4000
#CSIDL_FLAG_CREATE = $8000
#CSIDL_FLAG_MASK = $FF00

Structure ****EMID
    cb.b
    abID.b[1]
EndStructure

Structure ITEMIDLIST
    mkid.****EMID
EndStructure

Procedure.s GetSystemFolder (folder)
    *itemid.ITEMIDLIST = #NULL
    If SHGetSpecialFolderLocation_ (0, folder, @*itemid) = #NOERROR
        location$ = Space (#MAX_PATH)
        If SHGetPathFromIDList_ (*itemid, @location$)
            ProcedureReturn location$
        EndIf
    EndIf
EndProcedure

; D E M O . . .

folder$ = GetSystemFolder (#CSIDL_PERSONAL)
MessageRequester ("Result...", "The 'My Documents' folder is located in " + Chr (34) + folder$ + Chr (34), #MB_ICONINFORMATION)
End



--
See ya,
James L Boyd.
http://www.hi-toro.com/
--

Author:  dashunbaba [ Tue Dec 20, 2011 4:37 pm ]
Post subject:  Re: Get system folder location...

a simpler api is

SHGetSpecialFolderPath_

http://msdn.microsoft.com/en-us/library ... 04(v=vs.85).aspx

Author:  Bisonte [ Wed Dec 21, 2011 3:48 am ]
Post subject:  Re:

psst ....
BackupUser wrote:
Posted: Sun Feb 16, 2003 10:31 pm


;)

Author:  Kwai chang caine [ Fri Dec 23, 2011 8:41 pm ]
Post subject:  Re: Get system folder location...

Quote:
psst ....
:lol:

Author:  MachineCode [ Sat Dec 24, 2011 2:06 am ]
Post subject:  Re: Re:

Bisonte wrote:
psst ....
BackupUser wrote:
Posted: Sun Feb 16, 2003 10:31 pm

So what? Why do people think we can't reply to old posts? If new information makes an old tip better, then great!

Author:  Kwai chang caine [ Sun Dec 25, 2011 11:27 am ]
Post subject:  Re: Get system folder location...

Quote:
If new information makes an old tip better, then great!
Yes you have right, i don't know but perhaps the API not exist at that time "2003"

Author:  MachineCode [ Sun Dec 25, 2011 11:48 am ]
Post subject:  Re: Get system folder location...

Kwaï chang caïne wrote:
perhaps the API not exist at that time "2003"

It sure did:

MSDN wrote:
Minimum supported client: Windows 2000 Professional

Author:  Kwai chang caine [ Sun Dec 25, 2011 1:05 pm ]
Post subject:  Re: Get system folder location...

I don't know...then it's perhaps the reason of the "Psst" ... :wink: :lol:

Author:  yrreti [ Sun Dec 25, 2011 3:27 pm ]
Post subject:  Re: Get system folder location...

It's nice that some one thought enough to share some older code that he happened to come across.
We can always learn from it, as it shows different approaches. For instance, If you have Droopys lib
installed. It has the command GetSpecialFolderLocation.
So the following code, is all that is needed.
example:
Code:
#CSIDL_DESKTOPDIRECTORY = $10
#CSIDL_APPDATA = $1A
#CSIDL_PERSONAL = $5
Debug GetSpecialFolderLocation(#CSIDL_COMMON_DESKTOPDIRECTORY)
Debug GetSpecialFolderLocation(#CSIDL_APPDATA)
Debug GetSpecialFolderLocation(#CSIDL_PERSONAL)

Author:  Bisonte [ Sun Dec 25, 2011 3:50 pm ]
Post subject:  Re: Get system folder location...

And to complete this old thread, my used method (from ts-soft) :
Code:
Procedure.s GetSpecialFolder(CSIDL)
  ;> -- Author : ts-soft
  ;> -- german forum
  Protected *itemid.ITEMIDLIST
  Protected location.s = Space(#MAX_PATH)
 
  If SHGetSpecialFolderLocation_ (0, CSIDL, @*itemid) = #NOERROR
    If SHGetPathFromIDList_(*itemid, @location)
      CoTaskMemFree_(*itemid)
      If Right(location, 1) <> "\" : location + "\" : EndIf
      ProcedureReturn location
    EndIf
  EndIf
 
EndProcedure

and nearly the whole CSIDL Constants are already defined in PB...

Author:  jpfez [ Sat Oct 12, 2013 5:54 pm ]
Post subject:  Re: Get system folder location...

Sorry For re-bumping an old (ancient) thread. But I found another simpler way.
Code:
; ONLY FOR WINDOWS
; This constants enumeration could be deleted (seems that they are already declared in Purebasic)
Enumeration $1
  #CSIDL_INTERNET
  #CSIDL_PROGRAMS
  #CSIDL_CONTROLS
  #CSIDL_PRINTERS
  #CSIDL_PERSONAL
  #CSIDL_FAVORITES
  #CSIDL_STARTUP
  #CSIDL_RECENT
  #CSIDL_SENDTO
  #CSIDL_BITBUCKET
  #CSIDL_STARTMENU
  #CSIDL_MYDOCUMENTS
  #CSIDL_MYMUSIC
  #CSIDL_MYVIDEO
  #CSIDL_DESKTOPDIRECTORY = $10
  #CSIDL_DRIVES
  #CSIDL_NETWORK
  #CSIDL_NETHOOD
  #CSIDL_FONTS
  #CSIDL_TEMPLATES
  #CSIDL_COMMON_STARTMENU
  #CSIDL_COMMON_PROGRAMS
  #CSIDL_COMMON_STARTUP
  #CSIDL_COMMON_DESKTOPDIRECTORY
  #CSIDL_APPDATA
  #CSIDL_PRINTHOOD
  #CSIDL_LOCAL_APPDATA
  #CSIDL_ALTSTARTUP
  #CSIDL_COMMON_ALTSTARTUP
  #CSIDL_COMMON_FAVORITES
  #CSIDL_INTERNET_CACHE
  #CSIDL_COOKIES
  #CSIDL_HISTORY
  #CSIDL_COMMON_APPDATA
  #CSIDL_WINDOWS
  #CSIDL_SYSTEM
  #CSIDL_PROGRAM_FILES
  #CSIDL_MYPICTURES
  #CSIDL_PROFILE
  #CSIDL_SYSTEMX86
  #CSIDL_PROGRAM_FILESX86
  #CSIDL_PROGRAM_FILES_COMMON
  #CSIDL_PROGRAM_FILES_COMMONX86
  #CSIDL_COMMON_TEMPLATES
  #CSIDL_COMMON_DOCUMENTS
  #CSIDL_COMMON_ADMINTOOLS
  #CSIDL_ADMINTOOLS
  #CSIDL_CONNECTIONS
  #CSIDL_COMMON_MUSIC = $35
  #CSIDL_COMMON_PICTURES
  #CSIDL_COMMON_VIDEO
  #CSIDL_RESOURCES
  #CSIDL_RESOURCES_LOCALIZED
  #CSIDL_COMMON_OEM_LINKS
  #CSIDL_CDBURN_AREA
  #CSIDL_COMPUTERSNEARME = $3D
  #CSIDL_FLAG_PER_USER_INIT = $800
  #CSIDL_FLAG_NO_ALIAS = $1000
  #CSIDL_FLAG_DONT_VERIFY = $4000
  #CSIDL_FLAG_CREATE = $8000
  #CSIDL_FLAG_MASK = $FF00
EndEnumeration

Procedure.s GetFolderPath(FolderID.i)
  Protected FolderPath.s = Space(#MAX_PATH)
  SHGetFolderPath_(#NUL, FolderID, #NUL, #NUL, FolderPath)
  ProcedureReturn FolderPath
EndProcedure

;Now test if it works
Debug GetFolderPath(#CSIDL_COMMON_MUSIC)

Author:  IdeasVacuum [ Sat Oct 12, 2013 6:49 pm ]
Post subject:  Re: Get system folder location...

...but be aware that #CSIDL has been retired, it does not work in Windows8.
...this does, coded by GJ-68: http://www.purebasic.fr/english/viewtopic.php?f=5&t=55173

Author:  jpfez [ Sat Oct 12, 2013 7:17 pm ]
Post subject:  Re: Get system folder location...

IdeasVacuum wrote:
...but be aware that #CSIDL has been retired, it does not work in Windows8.
...this does, coded by GJ-68: http://www.purebasic.fr/english/viewtopic.php?f=5&t=55173

Thanks for the information and the URL, I didn't know that #CSIDL it's deprecated. I feel kind of dumb.

Author:  LinXP [ Wed Sep 23, 2020 4:44 pm ]
Post subject:  Re: Get system folder location...

Code:
Procedure.s GetSystemDirectory()
  Protected SystemDirectory.s = Space(#MAX_PATH)
  GetSystemDirectory_(SystemDirectory.s, #MAX_PATH)
  PathAddBackslash_(SystemDirectory.s)
  ProcedureReturn SystemDirectory.s
EndProcedure

Procedure.s GetWindowsDirectory()
  Protected WindowsDirectory.s = Space(#MAX_PATH)
  GetWindowsDirectory_(WindowsDirectory.s, #MAX_PATH)
  PathAddBackslash_(WindowsDirectory.s)
  ProcedureReturn WindowsDirectory.s
EndProcedure

Debug GetSystemDirectory()
Debug GetWindowsDirectory()

Page 1 of 1 All times are UTC + 1 hour
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/