Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#代码-如何计算ia.7z文件的数量_C#_File_Count_Directory_7zip - Fatal编程技术网

C#代码-如何计算ia.7z文件的数量

C#代码-如何计算ia.7z文件的数量,c#,file,count,directory,7zip,C#,File,Count,Directory,7zip,我正在寻找一种方法来打开一个.7z文件,并通过使用C#Code获得其中压缩内容的数量 string[] directoryPaths = Directory.GetDirectories(@"heregoesmypath"); foreach (string dircetory in directoryPaths) { int fileCount = (from file in Directory.EnumerateFiles(@dircetory, "*", SearchOption.

我正在寻找一种方法来打开一个.7z文件,并通过使用C#Code获得其中压缩内容的数量

string[] directoryPaths = Directory.GetDirectories(@"heregoesmypath");

foreach (string dircetory in directoryPaths)
{
   int fileCount = (from file in Directory.EnumerateFiles(@dircetory, "*", SearchOption.AllDirectories) select file).Count();

   string text = fileCount.ToString() + " Files of: " + "????" + " Files in Directory : " + dircetory;

try
{
   File.AppendAllText(_yourfile, text + Environment.NewLine + Environment.NewLine);
}

catch (Exception ex)
{
   MessageBox.Show(ex.ToString());
}
            string[] zippeddirectoryPaths = Directory.GetFiles(@"myresultpath");

            foreach (string exdircetory in zippeddirectoryPaths)
                {

                   // FileInfo info = new FileInfo(exdircetory);
                   // var test = info.Length;
                   // MessageBox.Show(test.ToString() + "Bytes");
                   // var test2 = info.Extension;
                   // MessageBox.Show(test2.ToString() + "Format");}
                   // var test3 = Empty;
                   // here must be a methode, which count my amount of files on the   
                   //  .7z file and save it in var test3
这是我到目前为止的代码。。。我需要的不是最后5行bevore,而是获取.7z文件中文件数的方法

以手动方式创建文件,您可以在7-Zip上执行右键单击go,然后单击open。 7-Zip UI将打开,并为您提供一个按钮属性。如果单击该按钮,将打开另一个窗口,其中显示文件和文件夹的数量

所以,如果我已经压缩了很多文件和文件夹,我根本不喜欢手动操作。我喜欢在C#中找到一种将结果保存在var中的方法,这样我可以在以后的代码中使用它们来编写日志

因此,请给我一些建议或示例代码来解决这个问题。

您可以使用从您自己开发的工具直接调用7z函数

另一种方法是使用和评估文本输出

呼叫示例:

7z.exe l Repository.7z > list.txt

...  
7-Zip 9.22 beta  Copyright (c) 1999-2011 Igor Pavlov  2011-04-18

Listing archive: Repository.7z

--
Path = Repository.7z
Type = 7z
Method = LZMA
Solid = +
Blocks = 1
Physical Size = 976726
Headers Size = 22453

   Date      Time    Attr         Size   Compressed  Name
------------------- ----- ------------ ------------  ------------------------
2011-08-31 15:57:36 ....A       663225       954273  Repository\codelists\version 0031\codelists.zip
2010-08-30 18:06:23 ....A        30936               Repository\...\map_ALOCAT_EG4003_Child.xml
2010-10-04 16:38:02 ....A        30936               Repository\...\map_ALOCAT_EG4003_Child.xml
.....
2011-09-09 10:40:14 D....            0            0  Repository\ALOCAT\EDIFACT
2011-09-09 10:56:25 D....            0            0  Repository\ALOCAT
2011-09-09 10:46:13 D....            0            0  Repository
------------------- ----- ------------ ------------  ------------------------
                             130869837       954273  895 files, 2167 folders
示例结果:

7z.exe l Repository.7z > list.txt

...  
7-Zip 9.22 beta  Copyright (c) 1999-2011 Igor Pavlov  2011-04-18

Listing archive: Repository.7z

--
Path = Repository.7z
Type = 7z
Method = LZMA
Solid = +
Blocks = 1
Physical Size = 976726
Headers Size = 22453

   Date      Time    Attr         Size   Compressed  Name
------------------- ----- ------------ ------------  ------------------------
2011-08-31 15:57:36 ....A       663225       954273  Repository\codelists\version 0031\codelists.zip
2010-08-30 18:06:23 ....A        30936               Repository\...\map_ALOCAT_EG4003_Child.xml
2010-10-04 16:38:02 ....A        30936               Repository\...\map_ALOCAT_EG4003_Child.xml
.....
2011-09-09 10:40:14 D....            0            0  Repository\ALOCAT\EDIFACT
2011-09-09 10:56:25 D....            0            0  Repository\ALOCAT
2011-09-09 10:46:13 D....            0            0  Repository
------------------- ----- ------------ ------------  ------------------------
                             130869837       954273  895 files, 2167 folders

发布一些到目前为止您已经完成的代码。至少在请求帮助之前尝试一下。结果看起来很好,但它似乎没有保存在变量中以用于进一步的代码,而且您也没有发布任何C代码。。。我还更新了我的问题,并向您展示了我已经创建的一小部分代码。如果你用C代码打电话,你能礼貌地把它贴出来,告诉我你用的是哪种参考资料吗?!参考7zSDK,我需要找到一个好的教程,解释如何在我的C#请求中安装和使用它。有什么建议吗?上面显示的示例输出是由7z.exe生成的,7z.exe是随7-zip提供的命令行工具。不涉及C#编码。其想法是,从程序中调用7z.exe并解释输出列表可能更容易。这将使您不必安装和理解7zSDK。