比如:D:\test里有1.txt,2.txt,3.txt......n.txt我想要的格式是,1.zip,2.zip,3.zip而且每一个zip文件里只有一个txt文件,而没有他的上一级的文件夹就教各位大神!!

解决方案 »

  1.   

    那换个问题吧!
    用cmd语句 实现这个功能,如图:谢谢了!!!!
      

  2.   


    /// <summary>
            ///  rar压缩
            /// </summary>
            /// <param name="file"></param>
            /// <param name="spath"></param>
            public static void rar(string file, string spath)
            {
                String the_rar;
                RegistryKey the_Reg;
                Object the_Obj;
                String the_Info;
                ProcessStartInfo the_StartInfo;
                Process the_Process;            the_Reg = Registry.ClassesRoot.OpenSubKey("Applications\\WinRAR.exe\\Shell\\Open\\Command");  //win2003 xp
                if (the_Reg == null)
                {
                    the_Reg = Registry.ClassesRoot.OpenSubKey("WinRAR\\Shell\\Open\\Command");  //server 2008/win7
                }            the_Obj = the_Reg.GetValue("");
                the_rar = the_Obj.ToString();
                the_Reg.Close();
                the_rar = the_rar.Substring(1, the_rar.Length - 7);            if (file.Equals("upload"))
                {
                    the_Info = " a  -ep -y " + "No-" + DateTime.Now.ToShortDateString().Replace('/', '-') + "-" + ".rar " + "  " + spath;
                }
                else
                {
                    the_Info = " a  -ep -y " + "No-" + DateTime.Now.ToShortDateString().Replace('/', '-') + "-" + ".rar " + "  " + spath;
                }            the_StartInfo = new ProcessStartInfo();
                the_StartInfo.FileName = the_rar;
                the_StartInfo.Arguments = the_Info;
                the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                the_StartInfo.WorkingDirectory = HttpContext.Current.Server.MapPath(@"..\..\" + file);//获取或设置要启动的进程的初始目录。
                the_Process = new Process();
                the_Process.StartInfo.UseShellExecute = false;
                the_Process.StartInfo.RedirectStandardInput = true;
                the_Process.StartInfo.RedirectStandardOutput = true;
                the_Process.StartInfo.RedirectStandardError = true;
                the_Process.StartInfo.ErrorDialog = false;
                the_Process.StartInfo.CreateNoWindow = true;
                the_Process.StartInfo = the_StartInfo;
                the_Process.Start();
                the_Process.WaitForExit();
                the_Process.Close();
            }
      

  3.   


    那是你方法写的不对
     String rarObjStr;
                RegistryKey rarRegKey;
                Object rarObj;
                StringBuilder commandInfo = new StringBuilder();
                ProcessStartInfo processInfo;
                Process process;            rarRegKey = Registry.ClassesRoot.OpenSubKey(@"WinRAR\Shell\Open\Command");
                rarObj = rarRegKey.GetValue("");
                rarObjStr = rarObj.ToString();
                rarRegKey.Close();
                rarObjStr = rarObjStr.Substring(1, rarObjStr.Length - 7);            commandInfo.Append(" a ");//压缩
                if (!File.Exists(toCompress))//非文件-处理所有子文件夹
                {
                    commandInfo.Append(" -r ");
                }
                if (sizeLimit > 0)//分卷压缩
                {
                    commandInfo.Append("-v");
                    commandInfo.Append(sizeLimit.ToString());
                    commandInfo.Append("m ");            }
                commandInfo.Append(compressedFileFullPath);
                commandInfo.Append(" ");
                commandInfo.Append(toCompress);            processInfo = new ProcessStartInfo();
                processInfo.FileName = rarObjStr;
                processInfo.Arguments = commandInfo.ToString();
                processInfo.WindowStyle = ProcessWindowStyle.Hidden;
                processInfo.WorkingDirectory = toCompress;
                process = new Process();
                process.StartInfo = processInfo;
                process.Start();
                process.WaitForExit();
      

  4.   

    你的情况,toCompress为遍历的完整文件名即可