C# 上传RAR文件 解压 获取解压后的文件名称

灰太狼 2022-01-09 21:23 408阅读 0赞

此方法适用于C盘windows文件夹中有WinRAR.exe文件

  1. if (fileExt.ToUpper() == ".RAR")
  2. {
  3. string zpath = Server.MapPath("~/SendFileZIP/");
  4. //不存在文件夹时创建文件夹
  5. if (!Directory.Exists(zpath))
  6. {
  7. Directory.CreateDirectory(zpath);
  8. }
  9. //导入rar 压缩文件时,清空SendFileZIP文件夹里面所有的文件
  10. DirectoryInfo clera = new DirectoryInfo(zpath);
  11. deletefileOrDic(clera);
  12. //解压 上传的rar文件
  13. int count = RARToFileEmail(zpath, filePath);
  14. //判断解压是否成功 解压出来的文件数量是否大于
  15. if (count > 0)
  16. {
  17. string[] strFiles = Directory.GetFiles(zpath);
  18. string strfiel = "";
  19. foreach (string item in strFiles)
  20. {
  21. DirectoryInfo dirtory = new DirectoryInfo(item);
  22. //获取不是文件夹时
  23. if (!dirtory.Exists)
  24. {
  25. strfiel = strfiel + item.ToString();
  26. break;
  27. }
  28. }
  29. string zname = Path.GetFileName(strfiel).ToString();//获取 解压后的文件的名称
  30. //解压后文件的名称
  31. string zFilePath = zpath + zname;
  32. }
  33. }

发表评论

表情:
评论列表 (有 0 条评论,408人围观)

还没有评论,来说两句吧...

相关阅读