I try to use file filter and directory filter to choose specified files and folders , but the files in sub folder are affected by file filter .
Example :
file filter : #"//1.txt$;2.txt$"
directory filter : #"//sub$"
Only 1.txt & 2.txt were compressed in sub folder , and i want all the files in sub folder compressed.
I assume that fastzip means the one class of SharpZipLib.
According to the documentation https://github.com/icsharpcode/SharpZipLib/wiki/FastZip the parameter for fileFilter is optional. If null is passed, all files in the specified folder should be compressed
Related
I want to add(and overwrite) all files including other folders that are in single folder.
Example:
In archive zip.zip:
work.docx
1.txt
Photos
|_ocean.png
|_horse.png
After adding files & folder from another folder it would be like:
work.docx
1.txt
code.cs
Photos
|_ocean.png
|_horse.png
Program
|_program.exe
|_config.txt
I tried to do that with Ionic's zip library:
Ionic.Zip.ZipFile zf = Ionic.Zip.ZipFile.Read(#"C:\\zip.zip");
zf.UpdateDirectory(#"C:\\Program");
zf.Save();
It works, but it doesn't overwrite files.
If you are using .NET 4.5 then you can use
System.IO.Compression.ZipArchive
It allows a single step compression.
ZipFile.CreateFromDirectory(#”C:\zip”, #”C:\zip.zip”);
To update it you can use ZipArchiveMode.Update
I am trying to add a file stored on my local disk to a 7-zip archive using SevenZipSharp and the 7z.dll. This file should be added to some path \a\b\c\... inside the archive. However, the CompressFiles method of SevenZipSharp's SevenZipCompressor does not seem to provide an overload for which the destination can be set.
How do I add a file to a specific path in a 7-zip archive using SevenZipSharp?
You can create in a temp folder your desired folder structure and the use the following:
SevenZipCompressor compressor = new SevenZipCompressor();
compressor.PreserveDirectoryRoot = true;
compressor.CompressionMode = CompressionMode.Create;
compressor.CompressDirectory(#"C:\Test", "ppp.zip");
In my example, I created many subfolders under "C:\Test", and as a result, I got the same folder structure in the zip file starting with root "\test..."
I want to zip some files in a directory. I have googled a lot but i always saw examples about zipping a directory (all files in directory) by the code below:
string startPath = #subPath;
string zipPath = #"C:\result.zip";
ZipFile.CreateFromDirectory(startPath, zipPath);
I am referencing System.IO.Compression.Filesystem.dll
This code zips all the files in the directory referenced by startPath.
I tried ZipArchive class for compressing but it compress file with directories on its path. For example,
assume i want to zip "a.txt" located at "C:\directories\Graphics\a.txt". The zip file contains directories "directories" and "Graphics" and into these directories the file "a.txt". It is not a good solution to cut files then erase the directories and paste again since i am working on big size data.
How can I zip only some of files at a directory?
How can I zip some files that are located in different directories?
I am looking up the subject for 2 days. Is it a kind of constraint in .Net?
You can use the ZipArchive class, first create it and then - once created you just add ZipArchiveEntry objects into the archive. Each of the ZipArchiveEntry objects represents a single file that you will add to the archive.
Some tips:
You can find more info and a sample of how this could be done on MSDN, here: http://msdn.microsoft.com/pl-pl/library/system.io.compression.ziparchive(v=vs.110).aspx and here: http://msdn.microsoft.com/pl-pl/library/system.io.compression.ziparchiveentry(v=vs.110).aspx.
This may not be an exact solution but should work for your scenario. I'll give you the steps :
Create a Temporary Directory
Read and copy your Selected files into the Temporary directory. This applies to your second scenario as well.
Zip the temporary directory
Delete Temporary Directory after you are done
I would recommend using File.Copy to copy all your desired files to a temporary directory, then zip them all from there and delete the temporary directory once the zip operation has finished.
I've two zip files in a folder
C:\WorkUnit\Network\Reports\
Zip files:
LatestReport-20140312_202854-NWTS-a345sfsd3353.zip
LatestReport-20140312_202854-NITS SPACE-d56shj67d3gt8p.zip
In each zip file i've few folders and log files
Lets take first zip file: LatestReport-20140312_202854-NWTS-a345sfsd3353.zip
Within the zip file and within the subFolders, text files are there.
CurrentStack\Unit\NWTS\
Service.txt
SpaceA.txt
SpaceB.txt
I need to check these text files at the above location is exists or not at this path "C:\Collection\LatestFiles\"
How can i check the textfiles existence(no content check)?
I need to zip a file in the folder c:\projects\test\test.log
I need to zip the test.log to a zip folder.I am using Ionic.zip.dll.
when I zipped the folder, it is entirely adding the folder c:\projects\test\test.log.
I need to add the test.log to a zip folder
for eg.jan.zip. it should contain only one file. no folder structure needed.
Thanks
Instead of
zipFile.AddFile(filename);
you should use
zipFile.AddFile(filename, "");
That will insert the file at the root of the zip file, ie without a path.