自动解压文件【马上接帖】

我辣椒哥 2011-05-16 04:28:57
Set Shell = Server.CreateObject("WScript.Shell")
rarcomm= "D:\email\page\mian\cmd.exe /c "&Mlpath&"rar.exe x -t -o+ -p- -e "
cmd=rarcomm&ywj&" "&ylj
'response.Write cmd
RetCode = Shell.Run(cmd,1, True)

上传123.rar到服务器名称修改成20111215.rar,执行到rar.exe x -t -o+ -p- -e将文件解压后得到的文件夹名称是123,如何解压20111215.rar得到的文件夹名称为20111215而不是123,如何修改呢???
...全文
82 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
子夜__ 2011-05-16
  • 打赏
  • 举报
回复
/// <summary>
/// 压缩方法
/// </summary>
/// <param name="patch">预压缩的路径</param>
/// <param name="rarPatch">压缩后的路径</param>
/// <param name="rarName">压缩文件名</param>
public static void RARsave(string patch, string rarPatch, string rarName)
{
String the_rar;
RegistryKey the_Reg;
Object the_Obj;
String the_Info;
ProcessStartInfo the_StartInfo;
Process the_Process;
try
{
the_Reg = Registry.ClassesRoot.OpenSubKey(@"Applications\\WinRAR.exe\\Shell\\Open\\Command");
the_Obj = the_Reg.GetValue("");
the_rar = the_Obj.ToString();
the_Reg.Close();
the_rar = the_rar.Substring(1, the_rar.Length - 7);
Directory.CreateDirectory(patch);
//命令参数

//the_Info = " a " + rarName + " " + @"C:Test?70821.txt"; //文件压缩

the_Info = " a " + rarName + " " + patch + " -r"; ;
the_StartInfo = new ProcessStartInfo();
the_StartInfo.FileName = the_rar;
the_StartInfo.Arguments = the_Info;
the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
//打包文件存放目录

the_StartInfo.WorkingDirectory = rarPatch;
the_Process = new Process();
the_Process.StartInfo = the_StartInfo;
the_Process.Start();
the_Process.WaitForExit();
the_Process.Close();
}
catch (Exception ex)
{
throw ex;
}
}

/// <summary>
///解 压缩方法
/// </summary>
/// <param name="patch">预解压缩的路径</param>
/// <param name="rarPatch">解压缩后的路径</param>

public static int unRAR(string unRarPatch, string rarPatch)
{

try
{
System.Diagnostics.Process Process1 = new System.Diagnostics.Process();
Process1.StartInfo.FileName = "Winrar.exe";
Process1.StartInfo.CreateNoWindow = true;
Process1.StartInfo.Arguments = " e " + unRarPatch + " " + rarPatch + " -y";
Process1.Start();
Process1.WaitForExit();
if (Process1.HasExited)
{
return Process1.ExitCode;
}
return -1000;
}
catch (Exception ex)
{
return -1001;
}
}


参考
bleach001 2011-05-16
  • 打赏
  • 举报
回复
如果压缩包名称是20111215那么解压出的文件夹就是20111215
我是这样理解的你只是把123.rar改名为20111215 但是123.rar里面包含一个123的文件夹,所以你解压20111215出现的是123.rar里面的123文件夹。你只是把压缩包的文件名改了而里面的内容没改?如果是这样的话,压缩前就应该改名,或者解压后改名
或者
也许是我理解错了
我辣椒哥 2011-05-16
  • 打赏
  • 举报
回复
rar.exe x -t -ad -o+ -p- -e

62,056

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧