我有一个要备份的文件,我没有任何东西“接触”我“知道”的文件。但我得到消息:
"The process cannot access the file 'C:\Cadence\SPB_Data\pcbenv\allegro.ilinit' because it is being used by another process
源代码:
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);
因此,只要程序到达这一行“System.IO.File.Copy(sourceFile, destFile, true);” 我得到了错误。有什么方法可以“强制”复制吗?