WINDOWS10: Finding a Folder

Just starting out? Need help? Post your questions and find answers here.
RichardL
Enthusiast
Enthusiast
Posts: 532
Joined: Sat Sep 11, 2004 11:54 am
Location: UK

WINDOWS10: Finding a Folder

Post by RichardL »

I have pensioned off my aging Windows 7 PC and moved to a newer machine that includes a rather small but very fast solid state drive for OS, programs and related storage. This disk is C:

I have a 1TB drive (D:) for files and data and assigned my Documents, Music etc to this drive.
Windows 10 makes the reassignment very easy... just a few clicks.

Although my Documents directory supposedly now lives on D: the utility I have used for years still returns C: and
another application (LibreOffice) also still defaults to C:

Can anyone tell me how to correctly detect the location of the currently assigned 'Documents' directory that will work with Windows 7 and 10

Thanks
RichardL

Code: Select all

Procedure.s SpecialFolder(CSIDL.l)          ; Ask Windows where it keeps various important files
  ;http://msdn.microsoft.com/en-us/library/windows/desktop/bb762494(v=vs.85).aspx
  
  ; Returns the path to a specified system directory.
  ; The calling parameter options can be found by looking in the Constants Explorer for #CDIDL_xxxxxx area.
  
  Protected *itemid.ITEMIDLIST
  Protected Location$ = Space(#MAX_PATH) 
  
  If SHGetSpecialFolderLocation_(0,CSIDL,@*itemid) = #NOERROR 
    If SHGetPathFromIDList_(*itemid,@Location$) 
      Debug "OK: "+Trim(Location$) + "\"
      ProcedureReturn Trim(Location$) + "\"
    Else
      Debug "ERROR: SHGetPathFromIDList() returned an error"
    EndIf 
  Else
    Debug "ERROR: SHGetSpecialFolderLocation() returned an error"
  EndIf 
  
  ProcedureReturn ""
EndProcedure 

k$ = "#CSIDL_DESKTOP:"        + Chr(9)+ SpecialFolder(#CSIDL_DESKTOP) + Chr(10)
k$ + "#CSIDL_COMMON_PICTURES:"+ Chr(9)+ SpecialFolder(#CSIDL_COMMON_PICTURES) + Chr(10)
k$ + "#CSIDL_PROGRAMS:"       + Chr(9)+ SpecialFolder(#CSIDL_PROGRAMS) + Chr(10)
k$ + "#CSIDL_HISTORY:"        + Chr(9)+ SpecialFolder(#CSIDL_HISTORY) + Chr(10)
k$ + "#CSIDL_DOCUMENTS:"      + Chr(9)+ SpecialFolder(#CSIDL_PERSONAL) + Chr(10)
k$ + "--------------------------------"

MessageRequester("Program Files",k$)
wombats
Enthusiast
Enthusiast
Posts: 716
Joined: Thu Dec 29, 2011 5:03 pm

Re: WINDOWS10: Finding a Folder

Post by wombats »

Does GetUserDirectory(#PB_Directory_Documents) (new in PB 5.60) work?
RichardL
Enthusiast
Enthusiast
Posts: 532
Joined: Sat Sep 11, 2004 11:54 am
Location: UK

Re: WINDOWS10: Finding a Folder

Post by RichardL »

This sorts it out:

https://www.howtogeek.com/howto/windows ... -easy-way/

Sorry for referencing the 'V' word!
Post Reply