提取用WinRAR ISO用C#或批量自动 [英] extract ISO with winrar automatically with c# or batch

查看:325
本文介绍了提取用WinRAR ISO用C#或批量自动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图提取的ISO到具有相同名称的文件夹,而不.ISO就结束。

I'm trying to extract an ISO to a folder with the same name without .iso on the end.

我在用winrar一个问题,因为它不会启动的时候,我开始了与SEACH与ISO的文件夹中开始提取。

I'm having a problem with winrar as it will not start the extract when I start up with the seach starting in the folder with the ISO.

与答案code更新时间:

private void ExtractISO(string toExtract, string folderName)
    {
        // reads the ISO
        CDReader Reader = new CDReader(File.Open(toExtract, FileMode.Open), true);
        // passes the root directory the folder name and the folder to extract
        ExtractDirectory(Reader.Root, folderName /*+ Path.GetFileNameWithoutExtension(toExtract)*/ + "\\", "");
        // clears reader and frees memory
        Reader.Dispose();
    }

    private void ExtractDirectory(DiscDirectoryInfo Dinfo, string RootPath, string PathinISO)
    {
        if (!string.IsNullOrWhiteSpace(PathinISO))
        {
            PathinISO += "\\" + Dinfo.Name;
        }
        RootPath += "\\" + Dinfo.Name;
        AppendDirectory(RootPath);
        foreach (DiscDirectoryInfo dinfo in Dinfo.GetDirectories())
        {
            ExtractDirectory(dinfo, RootPath, PathinISO);
        }
        foreach (DiscFileInfo finfo in Dinfo.GetFiles())
        {
            using (Stream FileStr = finfo.OpenRead())
            {
                using (FileStream Fs = File.Create(RootPath + "\\" + finfo.Name)) // Here you can Set the BufferSize Also e.g. File.Create(RootPath + "\\" + finfo.Name, 4 * 1024)
                {
                    FileStr.CopyTo(Fs, 4 * 1024); // Buffer Size is 4 * 1024 but you can modify it in your code as per your need
                }
            }
        }
    }

    static void AppendDirectory(string path)
    {
        try
        {
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
        }
        catch (DirectoryNotFoundException Ex)
        {
            AppendDirectory(Path.GetDirectoryName(path));
        }
        catch (PathTooLongException Ex)
        {
            AppendDirectory(Path.GetDirectoryName(path));
        }
    }

用户选择的文件夹中提取(.ISO)toExtract。然后,我在后台工作人员使用它的的Process.Start()。这似乎只是打开安装软件,并且不提取ISO到所需的文件夹名称。

The user selects the folder to extract (.ISO) toExtract. I then use it in the Process.Start() in the background worker. That just seems to open the mounting software and doesn't extract the ISO to the desired folder name.

在此先感谢您的帮助。

或者,如果任何人都可以给我一个批量提取ISO代替,并把它从C#传递toExtract,这将是有益的过于文件夹名称叫。

Or if anyone could give me a batch to extract the ISO instead and to call it from c# passing toExtract and the folder name that would be helpful too.

感谢

推荐答案

如果外部类库都OK!

然后使用 SevenZipSharp 或< A HREF =HTTP://discutils.$c$cplex.com/相对=nofollow> .NET DiscUtils 提取ISO的...

Then use SevenZipSharp or .NET DiscUtils to extract ISO's...

这两个ClassLibraries可以管理ISO和提取它们!

These two ClassLibraries can manage ISO and Extract them!

有关 DiscUtils 则可以在链接我找到了一些codeS为ISO管理[ CDReader 类]提供。

For DiscUtils you can find some codes for ISO Management [CDReader Class] at the Link I provided.

SevenZipSharp ,请浏览ClassLibrary源并找到code提取或谷歌找到它!

But For SevenZipSharp, Please Explore the ClassLibrary source and find the Code to Extract or Google to find it!

要获得文件夹的名称只使用 Path.GetFileNameWithoutExtension((字符串)ISOFileName)将返回ISOFile名为ISOFile.iso异。然后,你可以用你想要的路径中使用它。

To get the Name of the folder just use Path.GetFileNameWithoutExtension((string)ISOFileName) which will return "ISOFile" for an iso named "ISOFile.iso". And then you can use it with your desired path.

code要提取物DiscUtils ISO映像:

Code To Extract ISO Image with DiscUtils :

using DiscUtils;
using DiscUtils.Iso9660;

void ExtractISO(string ISOName, string ExtractionPath)
{
    using (FileStream ISOStream = File.Open(ISOName, FileMode.Open))
    {
        CDReader Reader = new CDReader(ISOStream, true, true);
        ExtractDirectory(Reader.Root, ExtractionPath + Path.GetFileNameWithoutExtension(ISOName) + "\\", "");
        Reader.Dispose();
    }
}
void ExtractDirectory(DiscDirectoryInfo Dinfo, string RootPath, string PathinISO)
{
    if (!string.IsNullOrWhiteSpace(PathinISO))
    {
        PathinISO += "\\" + Dinfo.Name;
    }
    RootPath += "\\" + Dinfo.Name;
    AppendDirectory(RootPath);
    foreach (DiscDirectoryInfo dinfo in Dinfo.GetDirectories())
    {
        ExtractDirectory(dinfo, RootPath, PathinISO);
    }
    foreach (DiscFileInfo finfo in Dinfo.GetFiles())
    {
            using (Stream FileStr = finfo.OpenRead())
            {
                using (FileStream Fs = File.Create(RootPath + "\\" + finfo.Name)) // Here you can Set the BufferSize Also e.g. File.Create(RootPath + "\\" + finfo.Name, 4 * 1024)
                {
                    FileStr.CopyTo(Fs, 4 * 1024); // Buffer Size is 4 * 1024 but you can modify it in your code as per your need
                }
            }
    }
}
static void AppendDirectory(string path)
{
    try
    {
        if (!Directory.Exists(path))
        {
            Directory.CreateDirectory(path);
        }
    }
    catch (DirectoryNotFoundException Ex)
    {
        AppendDirectory(Path.GetDirectoryName(path));
    }
    catch (PathTooLongException Exx)
    {
        AppendDirectory(Path.GetDirectoryName(path));
    }
}

使用它像这样的:

ExtractISO(ISOFileName, Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\");

工作!测试由我!

Working! Tested By Me!

当然,您也可以随时添加更多的优化到code ...

And Of Course You can always add more Optimization to the code...

这code是只是一个基本的一个!

This Code is Just a Basic One!

这篇关于提取用WinRAR ISO用C#或批量自动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆