現在、フォルダー構造をディレクトリにコピーするプログラムを作成しようとしています。
以下に例を示します
C:\test1\folder\folder\file.txt
。C:\test2\folder\folder\file.txt
Source-FolderがList<FileSystemInfo
あり、ファイルをコピーして、例のようにフォルダーを作成する必要があります。
ファイル名が 260 文字に制限されているため、パス名文字列なしでこれを行いたいと思います。
パス名を使用してファイルをコピーする次のコードがあります。
string destFile = BackupOptions.DestinationFolder + sourceFileInfo.FullName;
string destParent = Directory.GetParent(destFile).FullName;
string backupFolder = destParent + @ "\backupFolder";
try {
while (!Directory.Exists(destParent)) {
if (!Directory.Exists(destParent)) {
Directory.CreateDirectory(destParent);
}
}
FileAttributes fileAttributes = sourceFileInfo.Attributes;
if ((fileAttributes & FileAttributes.Directory) == FileAttributes.Directory) {
Directory.CreateDirectory(destFile);
} else {
FileInfo file = (FileInfo) sourceFileInfo;
file.CopyTo(destFile, true);
}
} catch (Exception e) {
Console.Write(e.Message);
return false;
}
そのファイル/オブジェクトの FileSystemInfo-Object だけでファイル/ディレクトリをコピーする方法を誰かが知っていますか?