pathlib icon indicating copy to clipboard operation
pathlib copied to clipboard

Send to recycling/trash folder

Open nemec opened this issue 8 years ago • 2 comments

In addition to deleting a file, it would be nice to be able to send it to the user's trash folder. The challenge in this one is that various OSes do things differently. Windows has the recycle bin, Linux has the trash folder (which can be in any number of places)

  • [ ] OSX holds it in ~/.Trash folder for main drive, other places for different mount points. Perhaps port the Trash application to C#.
  • [ ] Linus (and others using XDG spec) generally place it in .local/share/Trash, or mount-local directory.
  • [ ] Windows will probably use a PInvoke to native Win32 method since the Recycling Bin is a special GUID folder.
  • [ ] In case none of these work on the user's machine, need a good way to indicate failure. Perhaps by return value.

nemec avatar Nov 09 '17 04:11 nemec

How would you determine what OS the user is on? Would it be something like

if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
  // Do something
}

Would you want this feature added on all 'PathTypes'? IPurePath, Posix, etc

btw - this is cs_legend_93 from reddit. Thanks for recommending your library! it is by far the best

jeffward01 avatar May 01 '22 02:05 jeffward01

For Mac/Linux it would probably be enough to just check for the existence of the expected folders and use it if it exists - it's unlikely you'll find a ~/.local/share/Trash directory on Mac, for example, so small risk of false positives. Your suggestion is another option - I do something similar in some of the test cases.

I would put it as a method on the IPath interface, since it interacts with the filesystem. It would then be added as an abstract method on ConcretePath (since the implementation varies by OS) and finally the implementation for each platform falls in the PosixPath and WindowsPath classes. No changes to anything "Pure".

nemec avatar May 01 '22 08:05 nemec