C # List of files in the archive

I am creating a FileFinder class where you can perform a search as follows:

    var fileFinder = new FileFinder(
                         new string[]
                             {
                                  "C:\\MyFolder1",
                                  "C:\\MyFolder2" 
                             }, 
                         new string[]
                             {
                                  "*.txt",
                                  "*.doc"
                             } );
    fileFinder.FileFound += new EventHandler<FileFinderEventArgs>(FileFinder_FileFound);
    DoSearch();

If I executed this code, it FileFinder_FileFoundwill be called every time a file or is found in C:\\MyFolder1and its subfolders, or C:\\MyFolder2its subfolders .*.txt*.doc

The Sot class looks at subfolders, but I also want it to look at any zip files that it came across as if they were folders. How can i do this? It would be preferable that temporary files are not created ...

EDIT Forgot to mention that this is not a personal project; Its for commercial use I work with my company.

+3
source share
3 answers
+1

SharpZipLib: http://www.icsharpcode.net/opensource/sharpziplib/. ZIP , , .

.NET framework FileFinder .zip .

+1

.NET 4.5 , , , ZipArchive. System.IO.Compression. ZipFile, System.IO.Compression, System.IO.Compression.FileSystem ( ). MSDN: http://msdn.microsoft.com/en-us/library/system.io.compression.ziparchive%28v=vs.110%29.aspx

So, if your crawler encounters a zip file, you can do something like this (its essence):

using System;
using System.IO;
using System.IO.Compression;

using (ZipArchive archive = ZipFile.OpenRead(zipFilePath))
{
    foreach (ZipArchiveEntry entry in archive.Entries)
    {
        if (entry.FullName.EndsWith(".txt", StringComparison.OrdinalIgnoreCase) ||
            entry.FullName.EndsWith(".doc", StringComparison.OrdinalIgnoreCase))
        {
            // FileFinder_FileFound(new FileFinderEventArgs(...))
        }
    }
}
+1
source

Source: https://habr.com/ru/post/1772461/


All Articles