Move files in C#
I suggest you to use '@'
in order to escape slashes in a more readable way. Use also Path.Combine(...)
in order to concatenate paths and PadLeft
in order to have your filenames as your specifics.
for (int i = 1; i < n; i++)
{
try
{
from = System.IO.Path.Combine(@"E:\vid\","(" + i.ToString() + ").PNG");
to = System.IO.Path.Combine(@"E:\ConvertedFiles\",i.ToString().PadLeft(6,'0') + ".png");
File.Move(from, to); // Try to move
Console.WriteLine("Moved"); // Success
}
catch (IOException ex)
{
Console.WriteLine(ex); // Write error
}
}
Why don't you use something like this?
var folder = new DirectoryInfo(@"E:\vid\"));
if (folder.Exists)
{
var files = folder.GetFiles(".png");
files.toList().ForEach(f=>File.Move(from,to));
}