I have a file that I want to backup, I don't have anything "touching" the file that I "know" of. But I get the message:
"The process cannot access the file 'C:\Cadence\SPB_Data\pcbenv\allegro.ilinit' because it is being used by another process
Source Code:
string fileName = @"C:\Cadence\SPB_Data\pcbenv\allegro.ilinit";
string sourcePath = @"C:\Cadence\SPB_Data\pcbenv";
string targetPath = @"C:\Cadence\SPB_Data\pcbenv\backup";
// Use Path class to manipulate file and directory paths.
string sourceFile = System.IO.Path.Combine(sourcePath, fileName);
string destFile = System.IO.Path.Combine(targetPath, fileName);
// To copy a folder's contents to a new location:
// Create a new target folder, if necessary.
if (!System.IO.Directory.Exists(targetPath))
{
System.IO.Directory.CreateDirectory(targetPath);
}
// To copy a file to another location and
// overwrite the destination file if it already exists.
System.IO.File.Copy(sourceFile, destFile, true);
So as soon as the program hits this line " System.IO.File.Copy(sourceFile, destFile, true);" I get the error. Any way to "force" a copy ?