모든 파일을 복사하고 비어있는 폴더와 보호 된 파일, 파일, 보이지 않는 파일, 폴더 또는 파일을 복사하고 싶습니다. 모두 복사하십시오!어떻게 한 폴더의 모든 내용을 복사합니까 (파일 및 폴더 복사)
2
A
답변
4
방법 디렉토리를 복사하는 방법을 보여줍니다 MSDN's documentation of the DirectoryInfo class에서 가져온 다음 샘플 :
using System;
using System.IO;
class CopyDir
{
public static void CopyAll(DirectoryInfo source, DirectoryInfo target)
{
if (source.FullName.ToLower() == target.FullName.ToLower())
{
return;
}
// Check if the target directory exists, if not, create it.
if (Directory.Exists(target.FullName) == false)
{
Directory.CreateDirectory(target.FullName);
}
// Copy each file into it's new directory.
foreach (FileInfo fi in source.GetFiles())
{
Console.WriteLine(@"Copying {0}\{1}", target.FullName, fi.Name);
fi.CopyTo(Path.Combine(target.ToString(), fi.Name), true);
}
// Copy each subdirectory using recursion.
foreach (DirectoryInfo diSourceSubDir in source.GetDirectories())
{
DirectoryInfo nextTargetSubDir =
target.CreateSubdirectory(diSourceSubDir.Name);
CopyAll(diSourceSubDir, nextTargetSubDir);
}
}
public static void Main()
{
string sourceDirectory = @"c:\sourceDirectory";
string targetDirectory = @"c:\targetDirectory";
DirectoryInfo diSource = new DirectoryInfo(sourceDirectory);
DirectoryInfo diTarget = new DirectoryInfo(targetDirectory);
CopyAll(diSource, diTarget);
}
// Output will vary based on the contents of the source directory.
}
+0
그들은'string.Compare()'를 사용하지 않았다는 것에 놀랐습니다. – PostMan
2
관련 문제
- 1. 파일 내용을 다른 파일에 어떻게 복사합니까?
- 2. tfs에있는 폴더의 모든 내용을 나열
- 3. C - 한 폴더 내용을 다른 폴더로 복사
- 4. 지정된 폴더의 파일 및 폴더 삭제
- 5. 폴더의 모든 파일 열기
- 6. Ant에서는 폴더 트리의 모든 파일을 단일 폴더로 복사합니까?
- 7. 디렉터리 만들기 및 파일 복사
- 8. C# 폴더 및 폴더 내의 모든 파일 및 폴더 삭제
- 9. 파일을 어떻게 복사합니까?
- 10. 복사 폴더 내용
- 11. 특정 폴더에서 모든 파일 및 폴더 삭제
- 12. 어떻게 셀의 내용을 클립 보드에 복사합니까?
- 13. Vbscript - 대상 파일보다 새로운 경우 폴더의 파일 비교 및 복사
- 14. 한 도메인에서 다른 도메인으로 폴더의 이미지 복사
- 15. 폴더 내용을 HTML로 읽음
- 16. 폴더 지우기 - 폴더의 파일 지우기 - J2ME
- 17. iphone에있는 폴더의 모든 하위 폴더 반복하기
- 18. 파일 및 폴더 선택기
- 19. html이 폴더의 내용을 보여줍니다.
- 20. 힘내 : 다른 지점의 디렉토리에있는 모든 파일 복사
- 21. SHFileOperation이 폴더의 모든 내용을 이동하지 않습니다.
- 22. 모든 폴더 배치 파일에 복사 하시겠습니까?
- 23. TortoiseSVN : 한 지점의 내용을 다른 지점으로 복사
- 24. .svn 폴더 및 파일
- 25. 폴더의 파일 목록 가져 오기
- 26. 어떻게 하위 폴더 내용을 상위 폴더에 마운트합니까?
- 27. 한 문서의 내용을 다른 문서로 복사
- 28. 수정 한 날짜까지 Sharepoint에서 폴더 복사
- 29. 폴더 및 모든 파일/하위 디렉터리 삭제
- 30. 하나의 폴더에 중첩 된 폴더 내용을 재귀 적으로 복사 (터미널)
당신이 C# 또는 VB를 사용하고 있습니까? 귀하의 태그는 혼란 스럽습니다. – alexn
나는 두 언어를 프로그래밍하는 것을 이해하지 못한다. – angel