本文整理汇总了C#中System.IO.Abstractions.FileInfoBase.CopyTo方法的典型用法代码示例。如果您正苦于以下问题:C# FileInfoBase.CopyTo方法的具体用法?C# FileInfoBase.CopyTo怎么用?C# FileInfoBase.CopyTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.Abstractions.FileInfoBase
的用法示例。
在下文中一共展示了FileInfoBase.CopyTo方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CopyFileAndMoveOnFailure
private FileInfoBase CopyFileAndMoveOnFailure(FileInfoBase sourceFile, string destinationFilePath)
{
return TryFileFuncAndMoveFileOnFailure(() => sourceFile.CopyTo(destinationFilePath, overwrite: true), destinationFilePath);
}
示例2: SafeReadContents
private string SafeReadContents(string file, out FileInfoBase fileInfo)
{
try
{
fileInfo = this._fileSystem.FileInfo.FromFileName(file);
return this._fileSystem.File.ReadAllText(file);
}
catch (IOException)
{
fileInfo = this._fileSystem.FileInfo.FromFileName(file);
var tempFile = Path.Combine(Path.GetTempPath(), fileInfo.Name);
try
{
fileInfo.CopyTo(tempFile, true);
return this._fileSystem.File.ReadAllText(tempFile);
}
finally
{
if (this._fileSystem.File.Exists(tempFile))
{
this._fileSystem.File.Delete(tempFile);
}
}
}
}
示例3: SmartCopyFile
private void SmartCopyFile(FileInfoBase sourceFile, string path)
{
var destFile = sourceFile.CopyTo(path, overwrite: true);
if (!_options.CopyMetaData)
{
return;
}
// we remove the existing attributes, as 'read-only' will cause an exception when writing 'creationtime' an others.
var removeattr = sourceFile.Attributes;
destFile.Attributes = 0;
destFile.CreationTimeUtc = sourceFile.CreationTimeUtc;
destFile.LastWriteTimeUtc = sourceFile.LastWriteTimeUtc;
destFile.LastAccessTimeUtc = sourceFile.LastAccessTimeUtc;
destFile.Attributes = removeattr;
}