Search code examples
c#command-line7zip

How do i check if a file is password protected via 7zip?


I am using 7zip (command line) to look at zip/rar/7z files. I essentially check how many files and what extension it has. Than... i got to password protected files. When the entire file is password protected (so you can not look at the filenames or anything within) i know. However if i can see the file i can NOT tell if they are password protected. I zipped two files one with the other without a password. 7z l filename.zip shows the files in both zip the same

How do i detect if a file is password protected in an archive using 7zip?


Solution

  • Use sevenzipsharp. Its not really documented but its not hard to figure out.

    SevenZipExtractor.SetLibraryPath(@"path\7-Zip\7z.dll");
    using (var extractor = new SevenZipExtractor(fn1))
    {
            if(extractor.Check()) { //is not password protected