Exclude System Hardlinks from File.Copy

时间:2017-08-04 13:04:37

标签: c# user-profile file-copying hardlink

So my problem is that I want to export my user account. But inside C:\%user%\AppData\Local\ are System Hardlinks e.g.: Application Data which I obviously have no right to use them.

Is there a way to exclude those System Hardlinks from the copying process?

2 个答案:

答案 0 :(得分:0)

我不确定您对硬链接的意思,但这可能会对您有所帮助

foreach (var dir in new DirectoryInfo(@"c:\users\xxxxxx\AppData\Local").GetDirectories())
{
    if (dir.Attributes.HasFlag(FileAttributes.ReparsePoint))
    {
        Console.WriteLine(dir.Name + " is symbolic, skip it");
    }
    else
    {
        //do your copy here
    }
}

答案 1 :(得分:0)

所以我用PhoneRecord解决了这个问题,这样做Exception handling

way

由于我对FileInfo[] sourceFiles = null; try { sourceFiles = new DirectoryInfo(sourcePath).GetFiles(); } catch (Exception ex) { WriteLog(LogPath, ex + ""); return; } 有点新意,我在最初的几个小时内无法解决这个问题。

相关问题