Search/Get file without extracting


#1

Hi – is there a way to find a file and if exists get only that file without decompressing/un-archiving it?


#2

@mbalathandapani,

You can try using the following Aspose.ZIP for .NET code to determine if a File exits in ZIP archive or not:

bool flag = false;
string fileName = "file.pdf";

Archive o = new Archive(dataDir + "CompressSingleFile_out.zip");            
foreach(ArchiveEntry entry in o.Entries)
{
    if (entry.Name.Equals(fileName))
    {
        flag = true;
    }                
}

if (flag)
{
    Console.WriteLine("File found");
}
else
{
    Console.WriteLine("File not found");
} 

If this is not what you are asking about, then please elaborate your inquiry further by providing complete details of your usecase. What do you mean by ‘if exists get only that file without decompressing/un-archiving it’?


#3

Thanks. Is this is the only way? If I have an archive around 5000 entries and that would loop through all the entries (of course we could do a break; to get out) if that file doesn’t exist? Is there any performance cost associated with this?


#4

@mbalathandapani,

Yes, you need to iterate through each ArchiveEntry to be able to determine existence of a particular file. In this case, the processing time (performance) fully depends on your ZIP archives (number of files it contains etc). You may experiment on your end (using the latest version https://downloads.aspose.com/zip/net) to determine the exact performance cost of 5000 file archive vs small archive. Please let us know if we can be of any further assistance.