Martin Ortmayr 0 Posted April 22, 2022 I'm having trouble figuring out how to read / copy a file that is on the filesystem of an Android device plugged into a Win10 PC via USB. I can see the file using Windows Explorer as shown in the attached image. Usually I would just use a drive letter to open the file but in this case it has no drive letter. I've tried something like this but it gives an error: assignfile(tf,'"\\This PC\TC20\Internal shared storage\WXLog.log"'); reset(tf); //Exception EInOutError, I/O error 123 occurs here What's the proper way to do this? Thanks Share this post Link to post
Remy Lebeau 1396 Posted April 23, 2022 (edited) The device is not accessible via the host machine's file system. There is no local drive letter or UNC share assigned to the device, so you can't use filesystem-based functions to access the device's files. So, you will have to use alternative means of accessing the device's files, such as: Win32 Shell interfaces (IShellFolder/IShellItem, PIDLs, etc) - which is what Explorer uses. Introduction to the Shell Namespace Navigating the Shell Namespace IFileOperation::CopyItem() and IFileOperation::CopyItems Windows Portable Devices API Android Debug Bridge pull command Edited April 23, 2022 by Remy Lebeau 2 Share this post Link to post
kopernikus 0 Posted May 25, 2022 The components from Vcl.Shell.ShellCtrls.pas and this code snippet will do the job: procedure TMainForm.bbCopyClick(Sender: TObject); var i,n,j : integer; fileOp : IFileOperation; siSrcList : IShellItemArray; idList : array of PItemIDList; siSrcFile,siDestFolder : IShellItem; begin with ShellListView do if assigned(Selected) then begin n:=Selected.Index; if SelCount=1 then with SelectedFolder do begin OleCheck(SHCreateItemFromIDList(AbsoluteID,IShellItem,siSrcFile)); OleCheck(SHCreateItemFromParsingName(PChar(edDestDir.Text),nil,IShellItem,siDestFolder)); OleCheck(fileOp.CopyItem(siSrcFile,siDestFolder,pchar(DisplayName),nil)); OleCheck(fileOp.PerformOperations); end else begin SetLength(idList,SelCount); j:=0; OleCheck(CoCreateInstance(CLSID_FileOperation,nil,CLSCTX_ALL,IFileOperation,fileOp)); OleCheck(fileOp.SetOperationFlags(FOF_FILESONLY+FOF_NOCONFIRMMKDIR+FOF_NO_CONNECTED_ELEMENTS)); for i:=n to Items.Count-1 do if Items[i].Selected then begin idList[j]:=Folders[i].AbsoluteID; inc(j); end; OleCheck(SHCreateShellItemArrayFromIDLists(SelCount,@idList[0],siSrcList)); OleCheck(SHCreateItemFromParsingName(PChar(edDestDir.Text),nil,IShellItem,siDestFolder)); OleCheck(fileOp.CopyItems(siSrcList,siDestFolder)); OleCheck(fileOp.PerformOperations); idList:=nil; end; end; end; Share this post Link to post
kopernikus 0 Posted June 24, 2022 Update: procedure TMainForm.bbCopyClick(Sender: TObject); var i,n,j : integer; fileOp : IFileOperation; siSrcList : IShellItemArray; idList : array of PItemIDList; siSrcFile,siDestFolder : IShellItem; begin with ShellListView do if assigned(Selected) then begin n:=Selected.Index; OleCheck(CoCreateInstance(CLSID_FileOperation,nil,CLSCTX_ALL,IFileOperation,fileOp)); if SelCount=1 then with SelectedFolder do begin OleCheck(SHCreateItemFromIDList(AbsoluteID,IShellItem,siSrcFile)); OleCheck(SHCreateItemFromParsingName(PChar(edDestDir.Text),nil,IShellItem,siDestFolder)); OleCheck(fileOp.CopyItem(siSrcFile,siDestFolder,pchar(DisplayName),nil)); OleCheck(fileOp.PerformOperations); end else begin SetLength(idList,SelCount); j:=0; OleCheck(fileOp.SetOperationFlags(FOF_FILESONLY+FOF_NOCONFIRMMKDIR+FOF_NO_CONNECTED_ELEMENTS)); for i:=n to Items.Count-1 do if Items[i].Selected then begin idList[j]:=Folders[i].AbsoluteID; inc(j); end; OleCheck(SHCreateShellItemArrayFromIDLists(SelCount,@idList[0],siSrcList)); OleCheck(SHCreateItemFromParsingName(PChar(edDestDir.Text),nil,IShellItem,siDestFolder)); OleCheck(fileOp.CopyItems(siSrcList,siDestFolder)); OleCheck(fileOp.PerformOperations); idList:=nil; end; end; end; Share this post Link to post