简体   繁体   English

C#中的7-zip(7za.EXE)存档相同名称的文件并存储文件夹信息

[英]7-zip (7za.EXE) in C# to archive files of same name & store folder information

My software is supposed to collect files into a .zip or .7z archive using 7zip, but due to the nature of the software, there are a lot of files with the same name, but different directories like: 我的软件应该使用7zip将文件收集到.zip或.7z档案中,但是由于该软件的性质,很多文件具有相同的名称,但目录不同,例如:

D:\Software\Components\Station1\Alarms\Logs\ValvePressureSensor.xml
D:\Software\Components\Station1\Configurations\ValvePressureSensor.xml
D:\Software\Components\Station2\Alarms\Logs\ValvePressureSensor.xml

These files are stored in a list "FileList.lst" and I am calling 7-zip this way: 这些文件存储在列表“ FileList.lst”中,我以这种方式调用7-zip:

7za a -t7z "D:\Software\CollectedData\Diagnostics.7z" 
"@D:\Software\ZipTemp\FileList.lst"

So I'm wondering whether there is a way to keep the directories of each file when they are zipped to stop 7-zip from flagging duplicate files? 所以我想知道是否有一种方法可以压缩每个文件的目录以阻止7-zip标记重复文件?

I am aware of the workaround involving the removal of "D:\\" from the beginning of each file path, but this would be impossible manually as the "FileList.lst" is populated in the C# code with around 1500~3000 files (which aren't always the same files), and the FileList.lst is located in a temporary folder which is created, zipped, then destroyed dynamically. 我知道解决方法涉及从每个文件路径的开头删除“ D:\\”,但是手动操作是不可能的,因为在C#代码中填充了大约1500〜3000个文件(其中“ FileList.lst”并不总是相同的文件),并且FileList.lst位于创建,压缩然后动态销毁的临时文件夹中。 So I couldn't store the 7za.EXE in the same area. 因此,我无法将7za.EXE存储在同一区域中。 On top of that, the file list is used by another executable which does need the drives specified in the file paths. 最重要的是,文件列表由另一个确实需要文件路径中指定的驱动器的可执行文件使用。

I should mention that I am using Visual Studio 2005, C#2.0, and 7-zip v9.20. 我应该提到我正在使用Visual Studio 2005,C#2.0和7-zip v9.20。

EDIT: my question was fairly broad before, I should clarify that I'm switching from WinZip(due to licensing issues) so I recall that in WinZip If you add -p switch, WinZip will store folder information for all files added, not just for files from subfolders; 编辑:我的问题之前相当广泛,我应该澄清一下我是从WinZip切换(由于许可问题),所以我记得在WinZip中,如果添加-p开关,WinZip将存储所有已添加文件的文件夹信息,而不仅仅是用于子文件夹中的文件; the folder information will begin with the folder specified on the command line. 文件夹信息将从命令行上指定的文件夹开始。 Do you know of something similar in 7zip? 您知道7zip中类似的内容吗?

EDIT 2: turns out you cannot keep file folder info with 7-zip 编辑2:事实证明您不能使用7-zip保留文件夹信息

I am aware of the workaround involving the removal of "D:\\" from the beginning of each file path, but this would be impossible manually 我知道解决方法涉及从每个文件路径的开头删除“ D:\\”,但是手动无法实现

So remove it dynamically. 因此,请动态删除它。 If your paths are consistent, a simple path.Substring(3) will suffice. 如果您的路径一致,则只需一个简单的路径path.Substring(3)就足够了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM