0

I want to extract all .cab files inside a particular folder in c# .net

static int ExtractCabFiles()
    {



        try
        {

            Console.WriteLine("Extracting Cab files");
            string strCommand = @"extrac32.exe";
            var strArrCabDetails = new string[3];
            strArrCabDetails[0] = ConfigurationManager.AppSettings["Cab_Files_Path"];
            strArrCabDetails[1] = "/L";
            strArrCabDetails[2] = ConfigurationManager.AppSettings["Event_Files_Folder_Path"];

            WriteLog("Cab files path : " + ConfigurationManager.AppSettings["Cab_Files_Path"] + "", false, false);

            const string strArgsSeparator = " ";
            string strArgs = string.Join(strArgsSeparator, strArrCabDetails);

            Process process = new Process();
            process.StartInfo.FileName = strCommand;
            process.StartInfo.Arguments = strArgs;
            process.StartInfo.CreateNoWindow = true;
            process.StartInfo.UseShellExecute = false;
            process.StartInfo.RedirectStandardError = true;
            process.StartInfo.RedirectStandardOutput = true;
            WriteLog("Extract Command : " + strCommand + " " + strArgs + "", false, false);
            process.Start();

            //string strError = process.StandardError.ReadLine();
            iExitCode = process.ExitCode;


             }
        catch (Exception ex)
        {

        }
    }

This code will extract a single .cab file but I want to extract multiple .cab files from the folder.

leppie
  • 115,091
  • 17
  • 196
  • 297

1 Answers1

1

This is an old question but I faced the same problem

To extract multiple files just use a wild card and the expand command e.g.

expand "C:\InputFolder*.CAB" -I -F:* C:\OutputFolder

the -I is necessary if you want the file with the original name. Otherwise it will maintain the original CAB name(at least its what happens when the cat file only have one file). What i mean is if the name of the file is file.CAB the name of the output will be file.CAB and not file.txt asuming that the CAB file only have one file named file.txt. If you want to preserve also directory structure, change -I to -R

jucamo
  • 11
  • 1
  • 2