2013-03-07 4 views
1

저는이 시험을위한 프로그래밍 언어로 C#을 사용하고 있습니다.폴더를 클립 보드에 복사

Google 검색 결과에서 수많은 포럼과 다른 장소를 검색했습니다. 그러나, 내 질문에 대한 해결책을 찾을 수 없습니다.

필자는 FileExplorer를 가지고 있으며 컨텍스트 메뉴 스트립 구성 요소에 복사/붙여 넣기/삭제 메뉴 항목이 있습니다. 이제 파일 탐색기에서 파일 복사 작업이 있지만 폴더를 복사하는 방법을 찾으려고합니다.

TreeView 구성 요소가 연결되는 기본 구성 요소로 사용하고 있습니다.

파일 탐색기 란 무엇입니까? 여기에 (이 내 파일 탐색기의 실제 이미지입니다) 내가 이야기하고 있습니다 :

enter image description here

여기 내 "FileExplorer \"폴더의 복사 '파일'내부에 내 현재 코드입니다. 또한 'FileExplorer \'폴더 안에있는 다른 폴더/파일을 검색합니다. 누군가가 나에게 내 파일 탐색기의 내부에 폴더를 복사하는 방법에 필요한 포인터/코드를 제공 할 수 있다면

private void toolStripMenuItemCopy_Click(object sender, EventArgs e) 
    { 
     try 
     { 
      DirectoryInfo[] directories = directoryInfo.GetDirectories(); 
      foreach (FileInfo file in directoryInfo.GetFiles()) // Retrieving the files inside of FileExplorer\ folder 
      { 
       if (file.Exists && file.Name == treeView.SelectedNode.Text) 
       { 
        StringCollection filePath = new StringCollection(); 
        filePath.Add(file.FullName); 
        Clipboard.SetFileDropList(filePath); // Copying the selected (node) file 
       } 
      } 

      if (directories.Length > 0) 
      { 
       foreach (DirectoryInfo directory in directories) // Retrieving the directories inside of the FileExplorer\ folder 
       { 
        foreach (FileInfo file in directory.GetFiles()) // Retreiving all the files inside of the directories 
         if (file.Exists && file.Name == treeView.SelectedNode.Text) 
         { 
          StringCollection filePath = new StringCollection(); 
          filePath.Add(file.FullName); 
          Clipboard.SetFileDropList(filePath); // Copying the selected (node) file 
         } 
       } 
      } 
     } 
     catch (Exception ex) 
     { 
      MessageBox.Show(ex.Message); 
     } 
    } 

도움을 주시면 감사하겠습니다!

답변

-1
StringCollection files = Clipboard.GetFileDropList(); 
foreach (string file in files) 
{ 
    if (System.IO.Directory.Exists(file)) 
    { 
     string destPath = info.FullName; 
     FileSystem.CopyDirectory(file, destPath, UIOption.AllDialogs, UICancelOption.DoNothing); 

    } 
} 
+0

몇 가지 설명을 추가하십시오. 코드가 작동해야하는 이유를 설명하십시오. – Nilambar

+0

설명하는 방법을 모르십시오. 그러나 시도해 봅시다. 원본 코드 경로에서 파일 및 디렉토리는 클립 보드에 저장됩니다. 질문은 "폴더 대처 방법"입니다. 코드 예제는 클립 보드의 모든 경로를 분석하고, 폴더를 선택하고 폴더를 대상 경로로 복사합니다. 이 경우 정확한 목적지 경로에 대한 책임은 귀하에게 있습니다. –

1

VB.NET 것은

Dim f() As String = {"C:\SureFire\TWHomepage"} 
Dim d As New DataObject(DataFormats.FileDrop, f) 
Clipboard.SetDataObject(d, True)