【问题标题】:Get all information from compressed files (C#)从压缩文件中获取所有信息 (C#)
【发布时间】:2013-12-11 07:17:49
【问题描述】:

我目前正在开发一个简单的应用程序,在该应用程序中浏览目录,然后将列出该目录中包含的所有文件。我使用 Path.GetFilename 和其他东西来获取每个文件的描述。现在我在想,压缩文件呢?我想窥视压缩文件(zip,rar)并获取我可以获得的所有文件信息。我该怎么做?

到目前为止,这是我的代码:

if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
        {
            button1.Enabled = true;
            this.dataGridView1.Rows.Clear();
            dPaths = "";
            string[] filePaths = Directory.GetFiles(folderBrowserDialog1.SelectedPath, "*.*", SearchOption.AllDirectories);
            for (int y = 0; y < filePaths.Length; y++)
            {
                FileInfo fInfo = new FileInfo(filePaths[y]);


                if (Path.GetExtension(filePaths[y]) != ".zip" && Path.GetExtension(filePaths[y]) != ".rar")
                {
                    this.dataGridView1.Rows.Add(
                        Path.GetFileName(filePaths[y]),
                        Path.GetExtension(filePaths[y]),
                        fInfo.Length,
                        fInfo.LastWriteTime,
                        Path.GetDirectoryName(filePaths[y]));

                    dPaths = dPaths
                        + Path.GetFileName(filePaths[y]) + "?"
                        + Path.GetExtension(filePaths[y]) + "?"
                        + fInfo.Length + "?"
                        + fInfo.LastWriteTime + "?"
                        + Path.GetDirectoryName(filePaths[y])
                        + ";";
                    // Legend:
                    // ? = explode for files, in order: Filename FileExtension Filesize FileDateModified Filepath
                    // ; = explode for every files
                }
                else //zip/rar detected, everything inside is not working though
                {
                    string[] compressedfile = Directory.GetFiles(filePaths[y], "*.*", SearchOption.AllDirectories);
                    for (int x = 0; x < compressedfile.Length; x++)
                    {
                        FileInfo fInfo2 = new FileInfo(compressedfile[x]);
                        this.dataGridView1.Rows.Add(
                        Path.GetFileName(compressedfile[x]),
                        Path.GetExtension(compressedfile[x]),
                        fInfo2.Length,
                        fInfo2.LastWriteTime,
                        Path.GetDirectoryName(compressedfile[x]));

                        dPaths = dPaths
                            + Path.GetFileName(compressedfile[x]) + "?"
                            + Path.GetExtension(compressedfile[x]) + "?"
                            + fInfo2.Length + "?"
                            + fInfo2.LastWriteTime + "?"
                            + Path.GetDirectoryName(compressedfile[x])
                            + ";";
                    }
                }
            }
        }

【问题讨论】:

    标签: c# zip rar


    【解决方案1】:

    对于 Zip 文件,您可以直接使用 .net。看看这篇优秀的文章: http://msdn.microsoft.com/en-us/library/system.io.compression.ziparchive(v=vs.110).aspx 对于 Rar 文件,您必须拥有第三方库。在 codeplex 有一个你应该看看

    http://sharpcompress.codeplex.com/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-01
      • 1970-01-01
      相关资源
      最近更新 更多