<P>FileInfo[] arrfileInfo = null;<BR>string[] dirList = Directory.GetDirectories(sourcePath);</P> <P>if (File.Exists(sourcePath))<BR>{<BR>arrfileInfo = new FileInfo[] { new FileInfo(sourcePath) };<BR>}<BR>else if(Directory.Exists(sourcePath))<BR>{<BR>DirectoryInfo di = new DirectoryInfo(sourcePath);<BR>arrfileInfo = di.GetFiles("*", SearchOption.AllDirectories);<BR>}</P> <P>foreach (string dir in dirList)<BR>{<BR>string dirName = dir.Substring(dir.LastIndexOf(@"") + 1);</P> <P>DirectoryInfo Dir = new DirectoryInfo(destPath + dirName);</P> <P>if (!Dir.Exists)<BR>{<BR>Directory.CreateDirectory(destPath + dirName);<BR>}<BR>}</P> <P>if (arrfileInfo != null)<BR>{<BR>long total_current = 0;<BR>long total = 0;</P> <P>// 총 파일 용량<BR>foreach (FileInfo i in arrfileInfo)<BR>{<BR>if ((i.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden)<BR>total += i.Length;<BR>}</P> <P>foreach (FileInfo i in arrfileInfo)<BR>{<BR>if ((i.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden)<BR>{<BR>continue;<BR>}</P> <P>FileStream rs = null, ws = null;</P> <P>try<BR>{<BR>rs = new FileStream(i.FullName, FileMode.Open);<BR>ws = new FileStream(destPath + "//" + i.Name, FileMode.Create);</P> <P>this.Invoke((SetLabelDelegate)delegate(string fileName)<BR>{<BR>lblFile.Text = fileName;<BR>}, new object[] {i.Name});</P> <P>int readSize = 0;<BR><BR>while((readSize = rs.Read(buffer, 0, buffer.Length)) != 0)<BR>{<BR>total_current += readSize;</P> <P>// ProgressBar<BR>int percent = (int)((double)total_current / (double)total * 100);</P> <P>this.Invoke((SetProgDelegate)delegate(int value)<BR>{<BR>this.pbTransfer.Value = value;<BR>this.lblPer.Text = String.Format("{0}%", value);<BR>},<BR>new object[] { percent });</P> <P>ws.Write(buffer, 0, readSize);<BR>}<BR>}<BR>catch(Exception e)<BR>{<BR>MessageBox.Show(e.ToString());<BR>}<BR>finally<BR>{<BR>try <BR>{ <BR>rs.Close(); <BR>}<BR>catch (Exception ex) <BR>{<BR>MessageBox.Show(ex.ToString());<BR>}<BR>try <BR>{ <BR>ws.Close(); <BR>}<BR>catch (Exception ex) <BR>{<BR>MessageBox.Show(ex.ToString());<BR>} <BR>}<BR>}<BR>this.Invoke((SetProgDelegate)delegate(int value) <BR>{ <BR>this.pbTransfer.Value = value; <BR>this.lblPer.Text = String.Format("{0}%", value); <BR>}, new object[] { 100 }); </P> <P>Thread.Sleep(500);<BR>}</P> <P>this.Invoke((ExitDelegate)delegate() <BR>{ <BR>this.DoEnd(); <BR>});</P> <P></P> <P>이런식으로 해서 파일복사를 했는데..</P> <P>폴더 생성도 잘 되고 복사도 잘 되는데..</P> <P></P> <P>ABC폴더 안에 [A폴더(파일있음), B폴더(파일있음), C.txt] 이런식으로 들어 있을 때 </P> <P>A폴더 생성되고 B 폴더 생성되고 저 생성된 폴더 안에 들어가야할 파일들도 c.txt와 함께 ABC폴더에 복사가 되버렸는데요..</P> <P></P> <P> </P> <P>저 부분에서 어떤형태로 수정을 해 줘야 생성된 폴더안으로 파일이 복사가 될까요..;;</P> <P> </P> <P>맨날 간단한 화면개발만 하다가 이런거 하려니까..;; 공부가 너무 부족했다는 생각이 드네요</P> <P>게다가 C#은 얼마 해보지 않아서...</P>
댓글 분란 또는 분쟁 때문에 전체 댓글이 블라인드 처리되었습니다.