It is currently Sun Dec 06, 2020 2:27 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 14 posts ] 
Author Message
 Post subject:
PostPosted: Sun Feb 16, 2003 9:31 pm 
Offline
PureBasic Guru
PureBasic Guru

Joined: Tue Apr 22, 2003 7:42 pm
Posts: 16777133
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/
--


Top
 Profile  
Reply with quote  
 Post subject: Re: Get system folder location...
PostPosted: Tue Dec 20, 2011 4:37 pm 
Offline
New User
New User

Joined: Sun Dec 18, 2011 5:59 pm
Posts: 8
a simpler api is

SHGetSpecialFolderPath_

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


Top
 Profile  
Reply with quote  
 Post subject: Re:
PostPosted: Wed Dec 21, 2011 3:48 am 
Offline
Addict
Addict
User avatar

Joined: Tue Oct 09, 2007 2:15 am
Posts: 1144
psst ....
BackupUser wrote:
Posted: Sun Feb 16, 2003 10:31 pm


;)

_________________
PureBasic 5.72 LTS (Windows x86/x64) | Windows10 Pro x64 | Z370 Extreme4 | i7 8770k | 64GB RAM | iChill GeForce RTX 2080 Super | HAF XF Evo​​
English is not my native language... (I often use DeepL to translate my texts.)


Top
 Profile  
Reply with quote  
 Post subject: Re: Get system folder location...
PostPosted: Fri Dec 23, 2011 8:41 pm 
Offline
Addict
Addict
User avatar

Joined: Sun Nov 05, 2006 11:42 pm
Posts: 4808
Location: Lyon - France
Quote:
psst ....
:lol:

_________________
ImageThe happiness is a road...
Not a destination


Top
 Profile  
Reply with quote  
 Post subject: Re: Re:
PostPosted: Sat Dec 24, 2011 2:06 am 
Offline
Addict
Addict

Joined: Tue Feb 22, 2011 1:16 pm
Posts: 1482
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!

_________________
Microsoft Visual Basic only lasted 7 short years: 1991 to 1998.
PureBasic: Born in 1998 and still going strong to this very day!


Top
 Profile  
Reply with quote  
 Post subject: Re: Get system folder location...
PostPosted: Sun Dec 25, 2011 11:27 am 
Offline
Addict
Addict
User avatar

Joined: Sun Nov 05, 2006 11:42 pm
Posts: 4808
Location: Lyon - France
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"

_________________
ImageThe happiness is a road...
Not a destination


Top
 Profile  
Reply with quote  
 Post subject: Re: Get system folder location...
PostPosted: Sun Dec 25, 2011 11:48 am 
Offline
Addict
Addict

Joined: Tue Feb 22, 2011 1:16 pm
Posts: 1482
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

_________________
Microsoft Visual Basic only lasted 7 short years: 1991 to 1998.
PureBasic: Born in 1998 and still going strong to this very day!


Top
 Profile  
Reply with quote  
 Post subject: Re: Get system folder location...
PostPosted: Sun Dec 25, 2011 1:05 pm 
Offline
Addict
Addict
User avatar

Joined: Sun Nov 05, 2006 11:42 pm
Posts: 4808
Location: Lyon - France
I don't know...then it's perhaps the reason of the "Psst" ... :wink: :lol:

_________________
ImageThe happiness is a road...
Not a destination


Top
 Profile  
Reply with quote  
 Post subject: Re: Get system folder location...
PostPosted: Sun Dec 25, 2011 3:27 pm 
Offline
Enthusiast
Enthusiast

Joined: Tue Oct 31, 2006 4:34 am
Posts: 540
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)


Top
 Profile  
Reply with quote  
 Post subject: Re: Get system folder location...
PostPosted: Sun Dec 25, 2011 3:50 pm 
Offline
Addict
Addict
User avatar

Joined: Tue Oct 09, 2007 2:15 am
Posts: 1144
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...

_________________
PureBasic 5.72 LTS (Windows x86/x64) | Windows10 Pro x64 | Z370 Extreme4 | i7 8770k | 64GB RAM | iChill GeForce RTX 2080 Super | HAF XF Evo​​
English is not my native language... (I often use DeepL to translate my texts.)


Top
 Profile  
Reply with quote  
 Post subject: Re: Get system folder location...
PostPosted: Sat Oct 12, 2013 5:54 pm 
Offline
New User
New User
User avatar

Joined: Fri Feb 08, 2013 2:05 am
Posts: 6
Location: Spain
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)

_________________
MacBook White [ MacOS 10.9 | Ubuntu 12 | Windows 8 ]


Top
 Profile  
Reply with quote  
 Post subject: Re: Get system folder location...
PostPosted: Sat Oct 12, 2013 6:49 pm 
Offline
Always Here
Always Here

Joined: Fri Oct 23, 2009 2:33 am
Posts: 6263
Location: Wales, UK
...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

_________________
IdeasVacuum
If it sounds simple, you have not grasped the complexity.


Top
 Profile  
Reply with quote  
 Post subject: Re: Get system folder location...
PostPosted: Sat Oct 12, 2013 7:17 pm 
Offline
New User
New User
User avatar

Joined: Fri Feb 08, 2013 2:05 am
Posts: 6
Location: Spain
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.

_________________
MacBook White [ MacOS 10.9 | Ubuntu 12 | Windows 8 ]


Top
 Profile  
Reply with quote  
 Post subject: Re: Get system folder location...
PostPosted: Wed Sep 23, 2020 4:44 pm 
Offline
New User
New User

Joined: Mon May 07, 2018 9:58 am
Posts: 5
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()


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 14 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 25 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye