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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by Fritsl · Oct 10, 2016 at 12:52 PM · editorfilesfile-io

Stuck on MoveFileOrDirectory

Hi, this is what I'm trying to use to move a folder in C#:

https://docs.unity3d.com/ScriptReference/FileUtil.MoveFileOrDirectory.html

As test I have 2 folders in /Assets: A b No matter what I've tried, I get the rather non-explaining errors, like: IOException: Failed to Move File / Directory from '/A' to '/b/A'.

As far as I can tell, all of the following fail:

                       FileUtil.MoveFileOrDirectory("A", "b/A");
                       FileUtil.MoveFileOrDirectory("/A", "b/A");
                       FileUtil.MoveFileOrDirectory("A/", "b/A");
                       FileUtil.MoveFileOrDirectory("/A/", "b/A");

                       FileUtil.MoveFileOrDirectory("A", "/b/A");
                       FileUtil.MoveFileOrDirectory("/A", "/b/A");
                       FileUtil.MoveFileOrDirectory("A/", "/b/A");
                       FileUtil.MoveFileOrDirectory("/A/", "/b/A");

                       FileUtil.MoveFileOrDirectory("A", "/b/A/");
                       FileUtil.MoveFileOrDirectory("/A", "/b/A/");
                       FileUtil.MoveFileOrDirectory("A/", "/b/A/");
                       FileUtil.MoveFileOrDirectory("/A/", "/b/A/");

                       FileUtil.MoveFileOrDirectory("A", "b/");
                       FileUtil.MoveFileOrDirectory("/A", "b/");
                       FileUtil.MoveFileOrDirectory("A/", "b/");
                       FileUtil.MoveFileOrDirectory("/A/", "b/");

                       FileUtil.MoveFileOrDirectory("A", "/b");
                       FileUtil.MoveFileOrDirectory("/A", "/b");
                       FileUtil.MoveFileOrDirectory("A/", "/b");
                       FileUtil.MoveFileOrDirectory("/A/", "/b");

FileUtil.MoveFileOrDirectory(Application.dataPath + "/A", Application.dataPath + "/b/A");

FileUtil.MoveFileOrDirectory(Application.dataPath + "/A", Application.dataPath + "/b");

FileUtil.MoveFileOrDirectory(Application.dataPath + "/A", Application.dataPath + "/b/");

FileUtil.MoveFileOrDirectory(Application.dataPath + "/A/", Application.dataPath + "/b");

Any clues or actual working code (not like the Unity Docs(!)) would be much appreciated, thanks :)

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 bellicapax · Oct 10, 2016 at 03:45 PM

You have a couple lines of code in there that actually do work. Did you have them all in a line like this trying to execute after each other? If so, you wouldn't have made it to the lines that do work. Alternatively, you may have not refreshed your AssetDatabase and not noticed it did work. (These are just guesses)

With folders named "A" and "b" in my root Assets folder, I was able to successfully use the following code to move folder A into b: (Note that I was unable to successfully use a relative path even though the documentation says it's possible)

 using UnityEngine;
 using UnityEditor;
 
 public static class MoveFolder
 {
     [MenuItem("Example/Move A into b")]
     static void MoveAIntoB()
     {
         FileUtil.MoveFileOrDirectory(Application.dataPath + "/A", Application.dataPath + "/b/A");
         AssetDatabase.Refresh();
     }
 
     [MenuItem("Example/Move A out of b")]
     static void MoveAOutOfB()
     {
         FileUtil.MoveFileOrDirectory(Application.dataPath + "/b/A", Application.dataPath + "/A");
         AssetDatabase.Refresh();
     }
 }
 
Comment
Add comment · 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
0

Answer by Fritsl · Oct 10, 2016 at 03:58 PM

Hi @bellicapax thanks a lot for taking your time to try and solve this :)

I'm 'glad' to see that you could not make a relative path work either, something's wrong here.

I got the same errors as always, when running your code - I suspect you're on a PC, I am testing on OSX right now, will try on PC later.

Am looking at filing a bug, any one else's input would be appreciated.

Thanks.

Comment
Add comment · Show 2 · 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 bellicapax · Oct 10, 2016 at 04:08 PM 0
Share

Yes, I am running Unity on Windows.

avatar image Fritsl · Oct 10, 2016 at 07:33 PM 0
Share

Hmm.. For the next in same situation, I made this work, have no time to investigate further:

                       FileUtil.CopyFileOrDirectory(sourceFolder, destinyFolder);
                       AssetDatabase.Refresh();
                       FileUtil.DeleteFileOrDirectory(sourceFolder);
                       AssetDatabase.Refresh();

sourceFolder / destinyFolder na$$anonymous$$g:

Assets/folder/folder/sourceFolder

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

67 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

Related Questions

missing files our project? 1 Answer

How to tell android to open a file 0 Answers

How Do I Write to a Created File? 1 Answer

Show files extensions in project window 2 Answers

Event or Callback for when Files are moved. 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