extract ISO with winrar automatically with c# or batch

前端 未结 4 723
时光说笑
时光说笑 2021-01-20 02:36

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

I\'m having a problem with winrar as it will not start the extract when I start

4条回答
  •  青春惊慌失措
    2021-01-20 02:53

    For UDF or for making Windows ISO Files after servicing(DISM) with out needs the above accepted answer is not working for me so i tried this working method with DiscUtils

    using DiscUtils;
    public static void ReadIsoFile(string sIsoFile, string sDestinationRootPath)
            {
                Stream streamIsoFile = null;
                try
                {
                    streamIsoFile = new FileStream(sIsoFile, FileMode.Open);
                    DiscUtils.FileSystemInfo[] fsia = FileSystemManager.DetectDefaultFileSystems(streamIsoFile);
                    if (fsia.Length < 1)
                {
                    MessageBox.Show("No valid disc file system detected.");
                }
                else
                {
                    DiscFileSystem dfs = fsia[0].Open(streamIsoFile);                    
                    ReadIsoFolder(dfs, @"", sDestinationRootPath);
                    return;
                }
            }
            finally
            {
                if (streamIsoFile != null)
                {
                    streamIsoFile.Close();
                }
            }
        }
    
    public static void ReadIsoFolder(DiscFileSystem cdReader, string sIsoPath, string sDestinationRootPath)
        {
            try
            {
                string[] saFiles = cdReader.GetFiles(sIsoPath);
                foreach (string sFile in saFiles)
                {
                    DiscFileInfo dfiIso = cdReader.GetFileInfo(sFile);
                    string sDestinationPath = Path.Combine(sDestinationRootPath, dfiIso.DirectoryName.Substring(0, dfiIso.DirectoryName.Length - 1));
                    if (!Directory.Exists(sDestinationPath))
                    {
                        Directory.CreateDirectory(sDestinationPath);
                    }
                    string sDestinationFile = Path.Combine(sDestinationPath, dfiIso.Name);
                    SparseStream streamIsoFile = cdReader.OpenFile(sFile, FileMode.Open);
                    FileStream fsDest = new FileStream(sDestinationFile, FileMode.Create);
                    byte[] baData = new byte[0x4000];
                    while (true)
                    {
                        int nReadCount = streamIsoFile.Read(baData, 0, baData.Length);
                        if (nReadCount < 1)
                        {
                            break;
                        }
                        else
                        {
                            fsDest.Write(baData, 0, nReadCount);
                        }
                    }
                    streamIsoFile.Close();
                    fsDest.Close();
                }
                string[] saDirectories = cdReader.GetDirectories(sIsoPath);
                foreach (string sDirectory in saDirectories)
                {
                    ReadIsoFolder(cdReader, sDirectory, sDestinationRootPath);
                }
                return;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
    

    it has extracted from a application source ISOReader but modified for my requirements

    total source is available at http://www.java2s.com/Open-Source/CSharp_Free_CodeDownload/i/isoreader.zip

提交回复
热议问题