Search code examples
shellwinapilazarusfreepascal

Shell API to copy all files in a folder?


I am using FreePascal/Lazarus, and I am trying to find the correct ShlObj/ShellApi calls to copy all files from a Device's DCIM Folder (i.e. a Camera) to another folder on the filesystem.

Here is the code to select to select the device:

r:=  ShlObj.SHBrowseForFolder(x);

But from, there all I have is r, which is a LPITEMIDLIST variable.

Does anyone know the correct code to copy all files inside the Device's DCIM Folder 'r', to a destination folder (i.e. strDest)?

Note: I must use the ShellApi/ShlObj interface to do the copying


Solution

  • I assume that the PIDL specifies an item that is part of the file system, but I believe that is what you intend since you go on to say "copy all files". In which case, call SHGetPathFromIDList to obtain the file system path from the PIDL, and then call SHFileOperation to copy the files.

    If you want to perform copying at the shell level, and not be restricted to files, then it's a little more complex. Probably the simplest will be to use IFileOperation, specifically the CopyItem and CopyItems methods. You'll need to be able to go from a PIDL to an IShellItem which can be done with SHCreateItemFromIDList.