x


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

more ▼

asked Jan 12 '12 at 09:34 PM

AVividLight gravatar image

AVividLight
1.9k 68 99 128

(comments are locked)
10|3000 characters needed characters left

1 answer: sort oldest

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).

more ▼

answered Jan 12 '12 at 09:50 PM

syclamoth gravatar image

syclamoth
14.8k 7 15 80

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

Jan 14 '12 at 04:26 AM AVividLight
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x4139
x1355
x31
x1
x1

asked: Jan 12 '12 at 09:34 PM

Seen: 1305 times

Last Updated: Jan 14 '12 at 04:26 AM