/// <summary> /// 특정 폴더를 ZIP으로 압축 /// </summary> /// <param name="targetFolderPath">압축 대상 폴더 경로</param> /// <param name="zipFilePath">저장할 ZIP 파일 경로</param> /// <param name="password">압축 암호</param> /// <param name="isDeleteFolder">폴더 삭제 여부</param> /// <returns>압축 성공 여부</returns> public static bool ZipFiles(string targetFolderPath, string zipFilePath, string password, bool isDeleteFolder) { bool retVal = false; // 폴더가 존재하는 경우에만 수행. if (Directory.Exists(targetFolderPath)) { // 압축 대상 폴더의 파일 목록. ArrayList ar = GenerateFileList(targetFolderPath); // 압축 대상 폴더 경로의 길이 + 1 int TrimLength = (Directory.GetParent(targetFolderPath)).ToString().Length + 1; // find number of chars to remove. from orginal file path. remove '\' FileStream ostream; byte[] obuffer; string outPath = zipFilePath; // ZIP 스트림 생성. ZipOutputStream oZipStream = new ZipOutputStream(File.Create(outPath)); try { // 패스워드가 있는 경우 패스워드 지정. if (password != null && password != String.Empty) { oZipStream.Password = password; } oZipStream.SetLevel(9); // 암호화 레벨.(최대 압축) ZipEntry oZipEntry; foreach (string Fil in ar) { oZipEntry = new ZipEntry(Fil.Remove(0, TrimLength)); oZipStream.PutNextEntry(oZipEntry); // 파일인 경우. if (!Fil.EndsWith(@"/")) { ostream = File.OpenRead(Fil); obuffer = new byte[ostream.Length]; ostream.Read(obuffer, 0, obuffer.Length); oZipStream.Write(obuffer, 0, obuffer.Length); } } retVal = true; } catch { retVal = false; // 오류가 난 경우 생성 했던 파일을 삭제. if (File.Exists(outPath)) { File.Delete(outPath); } } finally { // 압축 종료. oZipStream.Finish(); oZipStream.Close(); } // 폴더 삭제를 원할 경우 폴더 삭제. if (isDeleteFolder) { try { Directory.Delete(targetFolderPath, true); } catch { } } } return(retVal); }
public static C.Fil ToClient(this Fil Entity) { return(new C.Fil(Entity.UsersID, Entity.Text, Entity.FilID, Entity.DateLigne)); }