Hey so lately i've been trying to move files from one folder to another but errors keep coming up. Both the loacation and destination folders are created, location has few .txt files
Here's what i've tried:
string path = @"C:\TESTmove\path";
string path2 = @"C:\TESTmove\destiny";
if (Directory.Exists (path))
{
foreach (string filename in Directory.GetFiles(path))
{
File.Move (filename, path2);
//Console.WriteLine (filename);
}
}
else
{
Console.WriteLine("Wrong place");
}
and I'm getting this error:
Cannot create a file when that file already exists.
You're creating the same file named "destiny" in the directory path "C:\TESTmove". (That's not what you want, but that's basically what the code you posted is going to do.)
Instead, include the filename when moving the file to the new location.
File.Move(filename, Path.Combine(path2, Path.GetFileName(filename)));