How to send a folder to the recycle bin via script

Directory.Delete() wipes folders from the disk. Is there any “normal” way to go about sending them to the recycle bin in Windows? All the libraries suggested on StackExchange aren’t included with Unity, though that could be a viable answer if it’s just a matter of bringing a dll into the project and using it?

If you want to go down the external library route then follow this guide from the Unity documentation that should cover everything you need to import a dll. Since you’re not creating the dlls yourself, you can start from the “Using the DLL” section.

There is a built-in UnityEngine function, not requiring DLL’s.
docs.unity3d.com/ScriptReference/Windows.Directory.Delete

For example:

using UnityEngine.Windows.Directory

then…

UnityEngine.Windows.Directory.Delete("FOLDER PATH");

Not sure if the ‘using’ is right, I just saw this in this documentation when looking for an alternative to the System.IO.Directory method.

Use this:

AssetDatabase.MoveAssetToTrash("path");

If the file is outside Assets folder:

System.IO.File.Move("path", "Assets/xxx");
AssetDatabase.Refresh();
AssetDatabase.MoveAssetToTrash("Assets/xxx");