Medic3000
Medic3000

Reputation: 786

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:

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:

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?

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. So I couldn't store the 7za.EXE in the same area. 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.

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; the folder information will begin with the folder specified on the command line. Do you know of something similar in 7zip?

EDIT 2: turns out you cannot keep file folder info with 7-zip

Upvotes: 0

Views: 1168

Answers (1)

user1479055
user1479055

Reputation:

I am aware of the workaround involving the removal of "D:\" from the beginning of each file path, but this would be impossible manually

So remove it dynamically. If your paths are consistent, a simple path.Substring(3) will suffice.

Upvotes: 3

Related Questions