如何使用 7zip C# 将多个文件夹归档到一个 Zip 文件中?
How can I archive multiple Folders into a single Zip File using 7zip C#?
我有多个文件夹路径:
SourceFilePath="C:\Users\Anuj\Desktop\PSI"
SourceFilePath1="C:\Users\Anuj\Desktop\Google"
SourceFilePath2="C:\Users\Anuj\Desktop\Isp"
我想使用 7zip 命令行代码和 Zip 密码压缩这些路径。
编辑:
//Declare and instantiate a new process component.
System.Diagnostics.Process proc;
proc = new System.Diagnostics.Process();
//Do not receive an event when the process exits.
proc.EnableRaisingEvents = false;
//The "/C" Tells Windows to Run The Command then Terminate
string strCmdLine;
strCmdLine = "/C cd c:\Program Files\7-Zip\ ";
strCmdLine += " & 7z a "// here i need help
System.Diagnostics.Process.Start("CMD.exe", strCmdLine);
proc.Close();
我实际做了什么:
var MultiplePathFolders=SourceFilePath+SourceFilePath1+SourceFilePath2
System.Diagnostics.Process proc;
proc = new System.Diagnostics.Process();
proc.EnableRaisingEvents = false;
string strCmdLine;
strCmdLine = "/C cd c:\Program Files\7-Zip\ ";
strCmdLine += " & 7z a " + SyncPath + "\" + ZipName + "-FileName.7z " + MultiplePathFolders + " -p" + DecryptedPassword + "";
System.Diagnostics.Process.Start("CMD.exe", strCmdLine);
proc.Close();
你可以这样做:
string yourPassWord = "Hello";
string yourZipPath="D:\my7z.7z"; // Your 7z file path
//string yourZipPath="D:\myZip.zip"; // Or your zip file path
System.Diagnostics.Process proc;
proc = new System.Diagnostics.Process();
proc.EnableRaisingEvents = false;
List<string> foldersAndFiles = new List<string>();
foldersAndFiles.Add("D:\F1"); // Add folder
foldersAndFiles.Add("D:\F2"); // Add folder
foldersAndFiles.Add("D:\file.txt"); // Add file
string cmd = "a -tzip -p\"" + yourPassWord + "\" \"" + your7zPath + "\"";
foreach(var item in foldersAndFiles)
{
cmd += " \"" + item + "\"";
}
proc.StartInfo.FileName
= "c:\Program Files\7-Zip\7z.exe"; // Be sure this file exist.
proc.StartInfo.Arguments = cmd;
proc.Start();
proc.Close();
我有多个文件夹路径:
SourceFilePath="C:\Users\Anuj\Desktop\PSI"
SourceFilePath1="C:\Users\Anuj\Desktop\Google"
SourceFilePath2="C:\Users\Anuj\Desktop\Isp"
我想使用 7zip 命令行代码和 Zip 密码压缩这些路径。
编辑:
//Declare and instantiate a new process component.
System.Diagnostics.Process proc;
proc = new System.Diagnostics.Process();
//Do not receive an event when the process exits.
proc.EnableRaisingEvents = false;
//The "/C" Tells Windows to Run The Command then Terminate
string strCmdLine;
strCmdLine = "/C cd c:\Program Files\7-Zip\ ";
strCmdLine += " & 7z a "// here i need help
System.Diagnostics.Process.Start("CMD.exe", strCmdLine);
proc.Close();
我实际做了什么:
var MultiplePathFolders=SourceFilePath+SourceFilePath1+SourceFilePath2
System.Diagnostics.Process proc;
proc = new System.Diagnostics.Process();
proc.EnableRaisingEvents = false;
string strCmdLine;
strCmdLine = "/C cd c:\Program Files\7-Zip\ ";
strCmdLine += " & 7z a " + SyncPath + "\" + ZipName + "-FileName.7z " + MultiplePathFolders + " -p" + DecryptedPassword + "";
System.Diagnostics.Process.Start("CMD.exe", strCmdLine);
proc.Close();
你可以这样做:
string yourPassWord = "Hello";
string yourZipPath="D:\my7z.7z"; // Your 7z file path
//string yourZipPath="D:\myZip.zip"; // Or your zip file path
System.Diagnostics.Process proc;
proc = new System.Diagnostics.Process();
proc.EnableRaisingEvents = false;
List<string> foldersAndFiles = new List<string>();
foldersAndFiles.Add("D:\F1"); // Add folder
foldersAndFiles.Add("D:\F2"); // Add folder
foldersAndFiles.Add("D:\file.txt"); // Add file
string cmd = "a -tzip -p\"" + yourPassWord + "\" \"" + your7zPath + "\"";
foreach(var item in foldersAndFiles)
{
cmd += " \"" + item + "\"";
}
proc.StartInfo.FileName
= "c:\Program Files\7-Zip\7z.exe"; // Be sure this file exist.
proc.StartInfo.Arguments = cmd;
proc.Start();
proc.Close();