首页 新闻 赞助 找找看

c#调用winrar采用文件列表(.lst)压缩文件总是不成功

0
悬赏园豆:40 [已关闭问题] 关闭于 2014-04-08 10:50

由于我要压缩的文件太多,不能直接用命令行字符串,只能把要压缩的文件地址(这些文件不在一个文件夹下,或则同一个文件夹下部分文件)放在一个.lst文件中,然后通过winrar读这个.lst文件进行压缩。我的部分源码如下。

public string CompressFile(string sourceFilesPaths, string compressFileSavePath, string compressFileName)
        {
            string s = string.Empty;
            String the_rar;
            RegistryKey the_Reg;
            System.Object the_Obj;
            String the_Info;
            ProcessStartInfo the_StartInfo;
            Process the_Process;
            string filePath = string.Empty;
            try
            {
                //使用注册表对象获取到WiNRar路径
                the_Reg = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\WinRAR.exe\");
                if (string.IsNullOrEmpty(the_Reg.GetValue("").ToString()))
                {
                    s = "未安装压缩工具winrar!";
                    the_Reg.Close();
                }
                else
                {
                    the_Obj = the_Reg.GetValue("");
                    the_rar = the_Obj.ToString();
                    //固实文件列表名
                    string rarfileListName = "jfRarFile" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".lst";
                    //固实文件列表地址 与压缩程序保存相同目录
                    filePath = the_rar.ToLower().Replace("winrar.exe", "") + rarfileListName;
                    //创建固实文件列表
                    CreateRarFiles(filePath, sourceFilesPaths);
                    the_Reg.Close();
                    the_Info = " a  " + compressFileName;
                    the_Info += "  @" + rarfileListName;
                    the_StartInfo = new ProcessStartInfo();
                    the_StartInfo.FileName = the_rar;
                    the_StartInfo.Arguments = the_Info;
                    the_StartInfo.WindowStyle = ProcessWindowStyle.Normal;//Hidden 隐藏样式
                    the_StartInfo.WorkingDirectory = compressFileSavePath;//压缩文件存放目录
                    the_Process = new Process();
                    the_Process.StartInfo = the_StartInfo;
                    the_Process.Start();
                    the_Process.WaitForExit();
                    the_Process.Close();
                }
            }
            catch (Exception ex)
            {
                s = ex.Message;
            }
            //压缩完成后清除固实文件列表
            File.Delete(filePath);
            return s;
        }

万物轮回之所的主页 万物轮回之所 | 菜鸟二级 | 园豆:204
提问于:2014-04-08 09:09
< >
分享
所有回答(1)
0

我自己已经解决了,列表文件(.lst)无论放在哪儿都得加上全路径才能成功读取到列表文件。

万物轮回之所 | 园豆:204 (菜鸟二级) | 2014-04-08 10:49
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册