-3

I have lots of .rar files with lots of folders inside them. I want to read the .rar files' names and enter them to get the folders' names, then enter the folders. I don't want to extract the .rar files.

Steve Wilkes
  • 7,085
  • 3
  • 29
  • 32
Programmer
  • 29
  • 7
  • Entering rar files means you have to extract them at least info temp folder. – Christian Klemm Apr 15 '16 at 05:30
  • I have a lot of rar file for this reason i dont have enough empty place for extracting rar file – Programmer Apr 15 '16 at 05:35
  • Then you have to delete old temps after extracting. Such things are known as rar bombs which could spam your pc... – Christian Klemm Apr 15 '16 at 05:36
  • okey and also i have a problem related to extracting, my all rar files path aaa.rar->b_folder -> c_folder -> d_folder -> z_file due this path to when i extract my rar files all of them seem like one folder – Programmer Apr 15 '16 at 05:42

1 Answers1

2

Try Nunrar. It has a streaming support which is what you're looking for. The example of counting the entries of an archive is in the link.

[Edit]

Note: You want to read and count rar file entries without extracting them, which is the following code does:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NUnrar;
using NUnrar.Archive;
using System.IO;

namespace NunrarSOF
{
    class Program
    {
        static void Main(string[] args)
        {
            RarArchive archive = RarArchive.Open(@"C:\Work\fileName.rar");
            int count = 0;
            //archive.Volumes.ToString();
            foreach (RarArchiveEntry entry in archive.Entries)
            {
                count++;
                Console.WriteLine(entry.FilePath);
            }
            Console.WriteLine(count);
        }
    }
}
Bassem
  • 820
  • 9
  • 17
  • I have tried it but my Nunrar extract all of my rar files like one folder But i want to extarct each rar file to different folders but i cannot do it – Programmer Apr 15 '16 at 06:02
  • 1
    @Sake Why, in your question, do you write 'I dont want to do extract rar files' if you now *do* want to extract them? – Rob Apr 15 '16 at 06:09
  • @Sake, do you want to use streaming or extracting? – Bassem Apr 15 '16 at 06:11
  • I want to enter rar file get folders name and files without extracting but chris579 tell "Entering rar files means you have to extract them at least info temp folder." – Programmer Apr 15 '16 at 06:15
  • @Sake, did you tried the example in the link? It is clear that Nunrar supports streaming (i.e. get rar files **without extracting**) which is what you are looking for! – Bassem Apr 15 '16 at 06:18
  • I tried but i couldnt add these codes to my project – Programmer Apr 15 '16 at 06:20
  • @Sake, Did you add the lib package using NuGet? It's simple; Right-click on your project on the Solution Explorer -> Manage NuGet. Then search for Nunrar, add it, add the reference `using ....;` Then use the code. Try and let us know! – Bassem Apr 15 '16 at 06:24
  • yes i have added , can you write which codes i have to add – Programmer Apr 15 '16 at 06:26
  • string[] a = Directory.GetDirectories(entry.FilePath); Additional information: Could not find a part of the path 'C:\Users\Sake.Home-PC\Documents\Visual Studio 2015\Projects\WindowsFormsApplication4\WindowsFormsApplication4\bin\Debug\ .rar files path – Programmer Apr 15 '16 at 07:08
  • @Sake, `Directory.GetDirectories(@"C:\foldername")`. The `GetDirectories` method should take a folder path not file path and not all the entires are folders to check use `entry.IsDirectory` property. – Bassem Apr 15 '16 at 07:12
  • @ Bassem Akl But i want to getdirectories inside .rar files – Programmer Apr 15 '16 at 07:31
  • @Sake, did you try to use the `if (entry.IsDirectory)` inside the loop and if true do your action? – Bassem Apr 15 '16 at 07:39
  • yes but i dont know what i have to do add next steps – Programmer Apr 15 '16 at 07:43
  • @Sake, from this point I think you should create a separate question; Add the successful code you already achieved and describe your new problem. – Bassem Apr 15 '16 at 07:46