반응형
특정경로에 있는 파일을 복사해주는 소스 예제입니다.
string sourceFolderPath = //이 경로에 있는 폴더의 내용을
string destinationFolderPath = //이 경로로 복사
//경로가 없는 경우 처리
if (System.IO.Directory.Exists(destinationFolderPath) == false || System.IO.Directory.Exists(sourceFolderPath) == false)
{
return;
}
//파일 내용 읽어오기
string[] fileArray = System.IO.Directory.GetFiles(sourceFolderPath);
foreach (string file in fileArray)
{
string fileName = System.IO.Path.GetFileName(file);
try
{
//파일명 생성
string destinationFileName = System.IO.Path.Combine(destinationFolderPath, fileName);
//파일 덮어쓰기로 복사 실행
System.IO.File.Copy(file, destinationFileName, true);
}
catch (Exception ex)
{
// 오류내용 기록
}
}
반응형
'C#' 카테고리의 다른 글
[C# 문제]Hello World! 를 출력하시오. (0) | 2021.10.06 |
---|---|
c# 월말일자 구하기 (0) | 2021.09.27 |
배열에 있는 String 값을 연결하는 방법 (0) | 2021.05.25 |
C# 대칭수(회문수 - Palindromic number ) 인지 확인하는 소스 (0) | 2020.10.26 |
C# 문자열을 특정 기호를 기준으로 split 하기 (0) | 2020.10.26 |
댓글