0

Send a File to the Recycle Bin being the obvious search result. I've tried the wrapper provided, but it has errors when brought into Unity, IntPtr doesn't compile for starters. I've also imported Microsoft.VisualBasic and it's dependant System.Deployment into my project and am successfully calling

Debug.Log(Microsoft.VisualBasic.FileIO.FileSystem.FileExists(path + "\\test.txt"));
Microsoft.VisualBasic.FileIO.FileSystem.DeleteFile(path + "\\test.txt", UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin);

but it just delete the file, it does not go to the recycle bin. Unity is running on the C drive, the project is also on the C drive. I've tried files and folders, and have tried RecycleOption.DeletePermanently, it does recognize the files and folders with the Debug, but nothing ever shows up in the recycle bin.

Kyle Postlewait
  • 123
  • 1
  • 12

2 Answers2

1

I found the simplest way to fix this problem, is to just add a recycle bin to the project.

Since Unity supports file names and path lengths longer than "Windows Explorer", it does not send items to the recycle bin, because the recycle bin would not be able to hold them.

This is a Win32 API limitation.

If you end up with two files of the same name in your Unity Recycle bin, create another recycle bin, or a child recycle bin.

Not a convenient solution, but it works!

The way I get around this personally, is I keep versions of my project as I go. Then I can go back to any previous version of my project.

Rigel
  • 11
  • 1
0

Send a File to the Recycle Bin is indeed the way to go. I found that simply

using System;

was missing from my attempts to use the FileOperationAPIWrapper script. I've since been successfully moving files to the recycle bin using it.

Kyle Postlewait
  • 123
  • 1
  • 12