nemec / pathlib

Path manipulation library for .Net
MIT License
63 stars 9 forks source link

Send to recycling/trash folder #10

Open nemec opened 7 years ago

nemec commented 7 years ago

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)

jeffward01 commented 2 years ago

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

nemec commented 2 years ago

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".