首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

解压有关问题

2013-03-21 
解压问题[codecsharp]public static bool StartUnRAR(string rarFile, string destinationDirectory, boo

解压问题

[code=csharp]public static bool StartUnRAR(string rarFile, string destinationDirectory, bool deleteRarFile)
        {
            RegistryKey regkey;
            Object regvalue;
            string cmd;
            ProcessStartInfo startinfo;
            Process process;
            string rarexe;
            try
            {
                // 如果不输入目录则释放到与压缩包同目录下
                if (destinationDirectory == null)
                {
                    destinationDirectory = Path.GetDirectoryName(rarFile);
                }



                regkey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\WinRAR.exe");
                regvalue = regkey.GetValue("");
                rarexe = regvalue.ToString();
                regkey.Close();
               // rarexe = rarexe.Substring(1, rarexe.Length - 7);//解压缩命令,相当于在要压缩文件(rarName)上点右键->WinRAR->解压到当前文件夹
                cmd = string.Format("x {0} {1} -y",
                                    rarFile,
                                    destinationDirectory);
                startinfo = new ProcessStartInfo();
                startinfo.FileName = rarexe;
                startinfo.Arguments = cmd;
                startinfo.WindowStyle = ProcessWindowStyle.Hidden;
                process = new Process();
                process.StartInfo = startinfo;
                process.Start();


                process.WaitForExit();

                process.Close();


                // 如果删除压缩文件
                if (deleteRarFile)
                {
                    if (File.Exists(rarFile))
                    {
                        File.SetAttributes(rarFile, FileAttributes.Normal);
                        File.Delete(rarFile);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception during processing: {0}", ex.Message);
                return false;
            }

            return true;
        }

[/code]
[解决办法]
把这个命令行复制在控制台中运行,有什么反应?

热点排行