E
e-jimmi
I'm having a lot of trouble try to move files from one directory to
another. See below test harness:
string[] Files = Directory.GetFiles(@"C:\Temp\Test1\",
"test*.txt");
string _BackUpPath = @"c:\Temp\Test2\";
try
{
foreach (string file in Files)
{
//FileInfo ofile = new FileInfo(file);
//ofile.CopyTo(_BackUpPath);
//File.Copy(file, _BackUpPath, true);
//File.Delete(Path.Combine(_BackUpPath,
Path.GetFileName(file)));
File.Move(file, _BackUpPath); // this throws an exception
//File.Delete(file);
}
}
catch (Exception E)
{
Error(E); // recursively climbs the exception stack to uncover
any nested exceptions
}
I'm getting a "Cannot create a file when that file already exists."
exception.
If I comment the File.Move out and uncomment the File.Copy I get a "The
target directory already exists." exceptions
I am able to Delete both files when I uncomment the Deletes so don't
believe there is a Permissions or Lock issue.
I've attempted to perform a file Delete on the destination directory
before attempting to do the copy / move with no luck.
Not sure where to go from here.
I'd be grateful for any assistance
PS. First time post so set me straight if I'm out of order.
thanks
JS
another. See below test harness:
string[] Files = Directory.GetFiles(@"C:\Temp\Test1\",
"test*.txt");
string _BackUpPath = @"c:\Temp\Test2\";
try
{
foreach (string file in Files)
{
//FileInfo ofile = new FileInfo(file);
//ofile.CopyTo(_BackUpPath);
//File.Copy(file, _BackUpPath, true);
//File.Delete(Path.Combine(_BackUpPath,
Path.GetFileName(file)));
File.Move(file, _BackUpPath); // this throws an exception
//File.Delete(file);
}
}
catch (Exception E)
{
Error(E); // recursively climbs the exception stack to uncover
any nested exceptions
}
I'm getting a "Cannot create a file when that file already exists."
exception.
If I comment the File.Move out and uncomment the File.Copy I get a "The
target directory already exists." exceptions
I am able to Delete both files when I uncomment the Deletes so don't
believe there is a Permissions or Lock issue.
I've attempted to perform a file Delete on the destination directory
before attempting to do the copy / move with no luck.
Not sure where to go from here.
I'd be grateful for any assistance
PS. First time post so set me straight if I'm out of order.
thanks
JS