How to get all files from archive folder? SharpCompress - c#

I have directory named "data" in zip archive, in this directory I have other directories
I need to get all directories from data and iterate through them and then get all files from this directories.
How can I do this?

Related

How to use FastZip compressing files and folders together?

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

Zip a folder with all its files and subfolders in it C# (DotNet 4.5)

I am trying to zip a folder with all its files and folders but its not working properly.
Here is the Folder i am trying to Zip it contains some files and a subfolder
and here is how i am doing it.
System.IO.Compression.ZipFile.CreateFromDirectory(DestPath, ZipPath,System.IO.Compression.CompressionLevel.Optimal,true);
but the result is this
It does not include xml file and the subfolder. Expected output should be like this
Is it possible to achieve without using an external library ?

How to zip selected files? not all the files in a directory in c#

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.

Text Files check within the zip file to another folder

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)?

c# avoid zip folder issue

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.

Categories