2017-09-19 2 views
1

한 PC에서 다른 PC로 파일을 복사하는 간단한 데스크톱 응용 프로그램을 작성하고 있습니다. Windows 10 재분석 지점, 특히 My Music에 문제가 있습니다. 간단한 코드 줄을 사용하여 도망 갈 것이라고 생각했습니다.Zip Windows 10 System.IO.Compression을 사용하여 재분석 지점을 포함하지 않는 문서 폴더

ZipFile.CreateFromDirectory(documentsFolder, docSavePath + @"\Documents.zip", CompressionLevel.Optimal, false); 

하지만 내 음악 폴더에서는 충돌이 발생하지 않습니다. 또한이 작업을 수행하는 여러 가지 방법을 시도해 보았습니다. 모두 동일한 결과 - 액세스가 거부되었습니다. 문서 폴더를 복사하거나 압축 할 수 있습니까? 나는 그것을 의심한다, 나는 방금 뭔가를 놓친다. 나는 상승 특권을 시도하고 그 중 하나를 작동하지 않았다. 누구든지이 작업을 수행하는 방법에 대한 예를 알고 있습니까?

+0

파일을 저장하려는 doc 저장 경로는 어디에 있습니까? –

+0

USB 드라이브에. 또는 사용자가 선택한 위치. –

답변

0

ReparsePoint 속성을 확인하는 방법은 비교적 쉽지만, 모든 파일을 반복하여 ZipArchive에 추가하는 방법을 함께 모아야했습니다. RecurseDirectory의 크레딧은 this answer입니다.

그런 다음 재 파일 특성에 대해 배운 내용을 추가했습니다.

private void documentBackup(string docSavePath) 
    { 
     if (File.Exists(docSavePath + @"\Documents.zip")) File.Delete(docSavePath + @"\Documents.zip"); 
     using (ZipArchive docZip = ZipFile.Open(docSavePath + "\\Documents.zip", ZipArchiveMode.Create)) 
     { 
      foreach (FileInfo goodFile in RecurseDirectory(documentsFolder)) 
      { 
       var destination = Path.Combine(goodFile.DirectoryName, goodFile.Name).Substring(documentsFolder.ToString().Length + 1); 
       docZip.CreateEntryFromFile(Path.Combine(goodFile.Directory.ToString(), goodFile.Name), destination);      
      } 
     } 
    } 


    public IEnumerable<FileInfo> RecurseDirectory(string path, List<FileInfo> currentData = null) 
    { 
     if (currentData == null) 
      currentData = new List<FileInfo>(); 

     var directory = new DirectoryInfo(path); 

     foreach (var file in directory.GetFiles()) 
      currentData.Add(file); 

     foreach (var d in directory.GetDirectories()) 
     { 
      if ((d.Attributes & FileAttributes.ReparsePoint) == FileAttributes.ReparsePoint) 
      { 
       continue; 
      } 
      else 
      { 
       RecurseDirectory(d.FullName, currentData); 
      } 
     } 

     return currentData; 
    } 

실행하는 데 시간이 오래 걸립니다. 그러나이 dang 문제를 며칠 동안보고 난 후에는 효과가 있습니다.