-
반응형
밑의 함수의 인자를 보시는것처러 처음에는 복사할 폴더 경로
다음인자는 복사되어지는 위치 그리고 마지막 인자는 true를 넣어주세요..ㅋㅋ
다 같이 공유하면서..ㅋㅋㅋ
그럼 수고하세요~~
/// <summary>
/// Floder Copy
/// </summary>
/// <param name="szSourceFolderPath"></param>
/// <param name="szDestinationFolderPath"></param>
/// <param name="bOverwrite"></param>
private void CopyFolder(string szSourceFolderPath, string szDestinationFolderPath, bool bOverwrite)
{
if (Directory.Exists(szSourceFolderPath))
{
if (Directory.Exists(szDestinationFolderPath + "\\" + (new DirectoryInfo(szSourceFolderPath).Name)) && (!bOverwrite))
throw new System.Exception("이미 존재하는 폴더 입니다.\r\n " + szDestinationFolderPath);
else if (!Directory.Exists(szDestinationFolderPath + "\\" + (new DirectoryInfo(szSourceFolderPath).Name)))
Directory.CreateDirectory(szDestinationFolderPath + "\\" + (new DirectoryInfo(szSourceFolderPath).Name));
// 모든 파일
FileInfo[] objFiA = (new DirectoryInfo(szSourceFolderPath).GetFiles());
foreach (FileInfo objFi in objFiA)
{
objFi.CopyTo(szDestinationFolderPath + "\\" + (new DirectoryInfo(szSourceFolderPath).Name) + "\\" + objFi.Name);
}
// 자식 폴더
DirectoryInfo[] objDiA = (new DirectoryInfo(szSourceFolderPath).GetDirectories());
foreach (DirectoryInfo objDi in objDiA)
{
CopyFolder(objDi.FullName, szDestinationFolderPath + "\\" + (new DirectoryInfo(szSourceFolderPath).Name), bOverwrite);
}
}
else
throw new System.Exception("복사할 폴더가 존재하지 않습니다.\r\n " + szSourceFolderPath);
}
주의!
사용하다 보니 용량이 큰 폴더인 경우, 하위디렉터리가 많은 경우 재귀함수구조로 인해 메모리를 엄청 잡아먹으면서 뻗을 수 있네요. -_-;;
win32 api를 이용한 방법을 쓰는게 좋겠네요.반응형'Dev > C#' 카테고리의 다른 글
[C# ] 파일업로드(FileUpload) 소스 (0) 2008.08.17 [C#] 원하는 길이로 좌측/우측 정렬시킨후 나머지 공간을 다른 문자로 채우기 (1) 2008.05.19 public, private, protected (0) 2008.03.19 C# 텍스트파일 라인 읽어들이기 (0) 2008.03.12 문자열 잘라서 말줄임(..) 붙이기 메소드 (0) 2008.03.04