Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by malkere · Jan 09, 2018 at 01:39 PM · deletefile-iodirectoryfilesystemrecycle

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?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by DanielAllison · Jan 09, 2018 at 01:51 PM

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.

Comment
Add comment · Show 6 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image malkere · Jan 09, 2018 at 11:00 PM 0
Share

I was pointed to VisualBasic.FileIO, Shell32 and others, but yes they all required importation of DLLs, so this article helps. Thank you. https://stackoverflow.com/questions/3282418/send-a-file-to-the-recycle-bin https://social.msdn.microsoft.com/Forums/vstudio/en-US/05e3628d-5d08-4cea-8821-d5302139cc0d/how-to-access-the-recyclebin-using-c?forum=csharpgeneral

avatar image DanielAllison malkere · Jan 10, 2018 at 11:07 AM 0
Share

Based on the links you sent, it looks like using the $$anonymous$$icrosoft.VisualBasic assembly and replacing your Directory.Delete() line with FileSystem.DeleteDirectoy("SomeDirectory", UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin) would do the trick.

Here's the documentation for the method if it's helpful - https://msdn.microsoft.com/en-us/library/ms127971(v=vs.110).aspx

avatar image malkere DanielAllison · Jan 10, 2018 at 01:58 PM 0
Share

I've imported $$anonymous$$icrosoft.VisualBasic.dll which required me to import System.Deployment.dll as well. Unfortunately the files do not go to the recycle bin =[ It does delete them though.... I tried using the DeletePermanently and SendToRecycleBin options on both folders and files after testing they exist using the FileSystem, but they just disappear =[ ??

Show more comments
avatar image malkere · Jan 09, 2018 at 11:01 PM 0
Share

I don't think there is any other/easier option is there? I mean I'd pay 5$ for an asset to do it for me honestly, a quick search really doesn't produce results though.

avatar image creganjordan292 malkere · Jan 10, 2018 at 02:01 PM 1
Share

Challenge accepted :P

avatar image
0

Answer by Honorsoft · Jan 10, 2018 at 04:09 PM

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image malkere · Jan 10, 2018 at 10:52 PM 0
Share

I don't have a Directory option via using nor typing out the whole reference? There is only Speech under UnityEngine.Windows? I'll look into it though. FYI, my target platform is set to Windows... Looks like I need to target Universal Windows Platform, not just PC/Linux/$$anonymous$$ac... fair for now... installing the addon...

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

77 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Incremental Filename if it exists 3 Answers

Saving File in new directory - Unauthorized Access Exception 1 Answer

Access existing folders android 0 Answers

How do I access music files on the Oculus Quest and play them? 0 Answers

Deleted assets not going to recycle bin 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges