2012-02-16 3 views
2

SharpZipLib을 사용하여 일부 폴더를 압축하려고합니다.SharpZipLib로 빈 디렉토리 팩

http://wiki.sharpdevelop.net/SharpZipLib-Zip-Samples.ashx#Create_a_Zip_with_full_control_over_contents_0

내가 directory3directory4없이 우편 아카이브를 얻을 : 여기에서 C# 코드를 사용하여 포장 할 때 예

directory1: 
    directory2: 
     file1 
    filde2 
    directory3: 
     directory4: 

을 stucture.

제 질문은 directory3directory4으로 아카이브를 가져올 수있는 방법입니다.

답변

2
FastZip fastZip = new FastZip(); 

fastZip.CreateEmptyDirectories = true; 
// Include all files by recursing through the directory structure 
bool recurse = true; 
// Dont filter any files at all 
string filter = null; 
fastZip.CreateZip("fileName.zip", @"C:\SourceDirectory", recurse, filter); 

주의해야 할 점은 UTF-8 파일 이름을 처리 할 수 ​​없다는 것입니다.

http://wiki.sharpdevelop.net/SharpZipLib_FastZip.ashx

+0

이름 만 utf-8이나 콘텐츠를 사용할 수 없습니까? utf-8 텍스트 파일 인'aa.txt'라는 이름의 파일을 팩 할 수 있습니까? – nirmus

+0

@nirmus - 파일 이름 만. –

+0

고맙습니다. 지금은 우편 번호가 비어 있습니다. 빈 디렉토리가 있지만, FastZip.ExtractZip을 사용하면 빈 디렉토리가 아닙니다.) 흥미 롭습니다. – nirmus

2

당신은 프로그램 항목으로 폴더를 추가 할 수 있습니다 : 여기

는 문서 위키에 대한 링크입니다.

각 폴더의 루프에 아래 코드를 추가하십시오.

//Here we create a path for a new entry, 
//but this time with the '\' in the end, its a folder 
string sEntry = sFolder.Substring(iFolderOffset) + "\\"; 
sEntry = ZipEntry.CleanName(sEntry); 
ZipEntry zeOutput = new ZipEntry(sEntry); 
zsOutput.PutNextEntry(zeOutput); 
zsOutput.CloseEntry(); 

아직 압축 해제를 테스트하지 않았습니다.