Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
1
Question by AVividLight · Jan 12, 2012 at 09:34 PM · c#arraysystem.io

Move files from folder a to folder b

Hey guys,

I am trying to create a temporary folder that users can put files into, then, when they click a button it moves the contents of the folder to a different folder on the users HardDrive. I believe it would work, except I am getting two errors, which I'll post bellow. Thanks for all your help, guys! Gibson

Variables:

 static string tempPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + Path.DirectorySeparatorChar + "Add To Unity Music Player";
 static public string macPath = "/Users/" + Environment.UserName + "/Documents/Unity Music Player Files/Media";
 //


Main code:

 void OnGUI ()
 {
             
     if (GUI.Button(new Rect(410, 70, 150, 30), "Add More Songs"))
     {
         
         Directory.CreateDirectory(tempPath);
         tempPathCreated = true;
         instructions.text = "Place the .wav files into\nthe folder on the desktop, then click done";
             
         }
     
     if (GUI.Button(new Rect(410, 110, 50, 20), "Done"))
     {
         if(tempPathCreated == false)
         {
             
             instructions.text = "No songs to move";
         
         } else {
             
             if(onMacintosh == true)
             {
                 
             File.Move (Directory.GetFiles(tempPath, "*.wav"), macPath);
                 
             } else {
                 
             }
         }
     }
 }
 //

Errors:

 Assets/Scripts/Manager.cs(99,38): error CS1502: The best overloaded method match for `System.IO.File.Copy(string, string)' has some invalid arguments
 
 Assets/Scripts/Manager.cs(99,38): error CS1503: Argument `#1' cannot convert `string[]' expression to type `string'
 //

Note, Line 99 is "File.Copy" line.

Thanks again ∆ Gibson

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

1 Reply

· Add your reply
  • Sort: 
avatar image
5
Best Answer

Answer by syclamoth · Jan 12, 2012 at 09:50 PM

Well, I assume you are talking about the 'File.Move' line, not 'File.Copy'...

In any case, the problem is fairly clear-

File.Move acts on a single file at a time, not an entire directory. The reason you get that error is because you are trying to feed an array of strings into a function that only accepts a single string as a parameter!

If you want to copy the operation over every single element in the array, you'll need to use a for loop, like this-

 foreach(String file in Directory.GetFiles(tempPath, "*.wav"))
 {
     File.Move (file, macPath);
 }

Then, the files will be moved one by one, instead of trying to do it all in one operation (which it doesn't actually know how to do).

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 AVividLight · Jan 14, 2012 at 04:26 AM 0
Share

Hey, thanks for the tip, also, sorry it took me so long to mark this as accepted.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Set default length for an array of elements of a custom class in inspector 0 Answers

Unity 3 GD HotShot-Tutorial Problem with an C#-Array 1 Answer

Array index help. 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