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

the 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

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