Move BEntry file to trash

What is the proper way for an app to send a file to the trash can, instead of deleting it completely?

void
MainWindow::DeleteCurrentImage()
{
   // Removed BAlert confirmation...

   if (fFileList.empty() || fCurrentIndex < 0)
	   return;

   entry_ref ref = fFileList[fCurrentIndex];
   BEntry entry(&ref);

   // TODO: Move to Trash
   status_t result = entry.Remove();

   if (result != B_OK) {
	   printf("Failed to delete image\n");
	   return;
   }
}

My guess would be MoveTo(), but how do I get the path to the trash?

If you’re OK with relying on a running Tracker, you could tell it to do it. Have a look at e.g. ShowImage’s ImageFileNavigator::MoveFileToTrash().

2 Likes

Yes, that’s probably where I should have looked to begin with :slight_smile:
Worked great. thanks.