티스토리 뷰
폴더내에 있는 모든 파일들을 하위파일/폴더 포함해서 싸그리 복사해서
다른 경로에 붙여넣는 클래스.
파일만 복사할꺼면 살짝? 만 손보면 됨.
복사가 되는 상태를 파일별로 보여주고 싶다면 BackgroundWorker를 이용해서 비동기로 작업하면 해결됨.
복사가 되는 상태를 파일별로 보여주고 싶다면 BackgroundWorker를 이용해서 비동기로 작업하면 해결됨.
///사용법/// 디렉토리 복사 /// /// 복사할 디렉토리 /// 복여넣을 디렉토리 /// true : 덮어씀, false : 덮어쓰지 않음 ///true :성공, false : 실패 private static bool CopyDirectory(string SourcePath, string DestinationPath, bool overwriteexisting) { bool ret = true; try { SourcePath = SourcePath.EndsWith(@"\") ? SourcePath : SourcePath + @"\"; DestinationPath = DestinationPath.EndsWith(@"\") ? DestinationPath : DestinationPath + @"\"; if (Directory.Exists(SourcePath)) { if (Directory.Exists(DestinationPath) == false) Directory.CreateDirectory(DestinationPath); foreach (string fls in Directory.GetFiles(SourcePath)) { FileInfo flinfo = new FileInfo(fls); flinfo.CopyTo(DestinationPath + flinfo.Name, overwriteexisting); } foreach (string drs in Directory.GetDirectories(SourcePath)) { DirectoryInfo drinfo = new DirectoryInfo(drs); if (CopyDirectory(drs, DestinationPath + drinfo.Name, overwriteexisting) == false) ret = false; } } else { ret = false; } } catch (Exception) { ret = false; } return ret; }
///폴더복사, 파일복사, 복사, filecopy/// 실제 복사작업이 이루어지는 비동기 함수 /// /// /// void worker_DoWork(object sender, DoWorkEventArgs e) { Cursor = Cursors.WaitCursor; string sourcePath = txtCopy.Text; // 복사할 폴더경로 string targetPath = txtPaste.Text; // 붙여넣을 폴더경로 CopyDirectory(sourcePath, targetPath, true); }
'프로그래밍 > .NetFramework' 카테고리의 다른 글
Delegate(델리게이트) Action<T>, Func<T> 간단사용법 (0) | 2014.03.12 |
---|---|
BackgroundWorker 사용법 (0) | 2014.02.10 |
C#에서 Internet explorer(IE) COM 객체로 핸들링하기. Win32API이용 (0) | 2013.05.06 |
64Bit Window 에서 32Bit ODBC 연결하기. (0) | 2012.10.18 |
BackgroundWorker, ProgressBar 활용 (0) | 2012.09.27 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- jQuery Mobile
- 셀렉터
- drag&drop
- 프로시저
- Ajax
- Chart
- radius
- JavaScript
- Mobile
- 저장프로시저
- MSSQL
- 자바스크립트
- grid
- CSS
- rowspan
- html5
- json
- IE
- ASP.NET
- workbook
- SVG
- Excel
- JS
- 제이쿼리
- Style
- WCF
- jQuery
- WebApi
- jquery chart
- css3
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 |
글 보관함