Lazarus

Programming => General => Topic started by: Borneq on January 24, 2020, 09:19:01 pm

Title: How get/read special paths?
Post by: Borneq on January 24, 2020, 09:19:01 pm
In open-file dialog , espacially on Windows, are special paths:
Desktop,Download, OneDrive etc
and network paths.
How to read network paths, iterate over network folders?
Title: Re: How get/read special paths?
Post by: Bart on January 24, 2020, 09:26:01 pm
Unit WinDirs has usefull functions for that IIRC.

Bart
Title: Re: How get/read special paths?
Post by: PascalDragon on January 25, 2020, 11:33:32 am
You need to retrieve a IShellItem instance for the special folder you want to list the contents of(in case of networks its CLSID_NETWORK). Then you need to enumerate the items of that instance. I currently can't provide you with any code as I'd have to piece it together myself again. However we've used such code at work, so I can show you the necessary functions/interfaces on Monday.

Please note that this will only enumerate those items that Windows discovered by itself as well (thus using the current user's credentials). This means that if NetBIOS browsing is disabled for example (which is the default in Windows 10) then you won't be able to find older shares (e.g. hosted by older NAS). Or if WS-Discovery is disabled on a Windows 7 you won't be able to see shares provided by Windows 10. You can see the used detection method by going to My Network Places, changing to Details view and then enabling the column Detection method (German: Erkennungsmethode). It will contain entries like WSD, NetBIOS and SSDP.
Title: Re: How get/read special paths?
Post by: Borneq on January 28, 2020, 10:44:09 pm
I need Windows dirs but also Linux dirs : Downloads , Documents, Uset home (tilda).
And need local network folders. Network especially in Windows, because VirtualBox shared folder for Windows is in network.
Wher can I get examples?
Title: Re: How get/read special paths?
Post by: mangakissa on January 29, 2020, 08:56:12 am
https://forum.lazarus.freepascal.org/index.php?topic=35841.0
https://forum.lazarus.freepascal.org/index.php?topic=25954.0
https://wiki.freepascal.org/Multiplatform_Programming_Guide
https://www.freepascal.org/docs-html/rtl/sysutils/getuserdir.html
Title: Re: How get/read special paths?
Post by: Borneq on January 29, 2020, 03:18:30 pm
Thanks.
In Linux , DVD and USB drives are usually mounted in /media but how read true mounting points?
In can't find how to read network dirs in Windows, probably I must use SHGetDesktopFolder.
Here is piece of very old my Delphi code: (about SHGetDesktopFolder but not related to networks)
Code: Pascal  [Select][+][-]
  1. var
  2.   FileInfo: TSHFileInfo;
  3.   ImageListHandle: THandle;
  4.   NewPIDL: PItemIDList;
  5. begin
  6.   OLECheck(SHGetDesktopFolder(FIDesktopFolder));
  7.   FIShellFolder := FIDesktopFolder;
  8.   FIDList := TList.Create;
  9.   ImageListHandle := SHGetFileInfo('',
  10.                            0,
  11.                            FileInfo,
  12.                            SizeOf(FileInfo),
  13.                            SHGFI_SYSICONINDEX or SHGFI_SMALLICON);
  14.   ImageList.Handle:=ImageListHandle;
  15. {  SendMessage(ListView.Handle, LVM_SETIMAGELIST, LVSIL_SMALL, ImageListHandle);
  16.  
  17.   ImageListHandle := SHGetFileInfo('C:\',
  18.                            0,
  19.                            FileInfo,
  20.                            SizeOf(FileInfo),
  21.                            SHGFI_SYSICONINDEX or SHGFI_LARGEICON);
  22.  
  23.  
  24.   SendMessage(ListView.Handle, LVM_SETIMAGELIST, LVSIL_NORMAL, ImageListHandle);}
  25.   OLECheck(
  26.     SHGetSpecialFolderLocation(
  27.       Application.Handle,
  28.       CSIDL_DRIVES,
  29.       NewPIDL)
  30.   );
  31.   SetPath(NewPIDL);
  32.   ActiveControl := cbPath;
  33.   cbPath.SelStart := 0;
  34.   cbPath.SelLength := Length(cbPath.Text);
  35.  
Title: Re: How get/read special paths?
Post by: winni on January 29, 2020, 03:31:46 pm
Hi!

In Linux you can read all mounted drives from

/proc/mounts

This is reaonly! And a loafFromFile will fail - read it one string after another!

The mountpoint for external drives is different in different distros.
It may be also /run/media

Winni
TinyPortal © 2005-2018