Link to home
Start Free TrialLog in
Avatar of robbiegrove
robbiegrove

asked on

Get share location from mapped drive letter

Just a quick question, how do I get the share location via Windows API by providing the drive letter?
This needs to work on all 9x and NTx Windows OS'

e.g: G: is mapped to \\mymachine\shares\something\photos, I want to get \\mymachine\shares\something\photos from the windows API by specfying G:

Thanks in advance
Robbie
Avatar of sun4sunday
sun4sunday
Flag of India image

//--------------------------------------

uses ShellAPI;


var
 opInfo : _SHFILEOPSTRUCT;

begin
     opInfo.pFrom := '\\mymachine\shares\something\photos'; //
 //    opInfo.pFrom := 'G:\shared folder name'; //you can set the like this also
      opInfo.pTo   := 'C:\Destination';  //DestinationFolder
      opInfo.wFunc :=  FO_COPY;  //Copy it
      opInfo.fFlags := FOF_NOCONFIRMATION  or //no confirmation Respond with "Yes to All" for any dialog box that is   displayed.
                       FOF_NOCONFIRMMKDIR or  //no confirmation  Do not confirm the creation of a new directory if the operation requires one to be created.
                       //FOF_FILESONLY or  //Perform the operation on files only if a wildcard file name (*.*) is specified
                       //FOF_RENAMEONCOLLISION or //rename if dest exist
                       //FOF_NOERRORUI or Do not display a user interface if an error occurs.
                       FOF_SIMPLEPROGRESS;  //show a progress
      opInfo.hNameMappings := nil;  // no mappings
      opInfo.fAnyOperationsAborted := False; //obsolete
      opInfo.lpszProgressTitle := 'Moving . . .';  //foo simpleprogressdisplay
      opInfo.Wnd := self.handle;  //the parent of the progressdisplay
      SHFileOperation(opInfo);  //do it

      if SHFileOperation(opInfo) <> 0 then RaiseLastOSError;
    end;

//-----------------------------

The above code works well to copy the entire folder.

Keep an eye on this https://www.experts-exchange.com/questions/21666726/Only-copy-jpg-from-a-folder.html

Make sure that the mapped drive is set to reconnect always.


sun4sunday
Avatar of robbiegrove
robbiegrove

ASKER

Errr I think you misunderstood the question mate..

I want the share location/path of a mapped drive letter.
E.g. simple example should be something along the lines of GetSharePath('G:') should return '\\mymachine\shares\something\photos'
Try using ExpandUNCFileName(strFileOrFolderName)
ASKER CERTIFIED SOLUTION
Avatar of sun4sunday
sun4sunday
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Very nice... :-)

And if you are looking at Windows 95 compatibility you can type out the rest of the GetUniversalName function in the SysUtils uit.. :-)

Bedouin..
Sun4Sunday's GetUNC() answer accepted :)
Thanks guys