如何指定多个文件扩展名来制作文件夹的rar? [英] How to specify multiple file extension for making rar of a folder?
问题描述
我正在使用c#代码制作文件夹的.rar文件。
I''m using c# code for making .rar file of a folder.
string zipFileToWrite, folderPath;
zipFileToWrite = @"D:\jack.rar";
folderPath = @"D:\TestFolder";
System.Diagnostics.Process MyProcess = new System.Diagnostics.Process();
MyProcess.StartInfo.WorkingDirectory = @"D:\NetworkPathChecking\FileBackup\FileBackup\bin\Debug\App_Files\";
MyProcess.StartInfo.FileName = "winrar.exe";
MyProcess.StartInfo.Arguments = "a -r " + "\"" + zipFileToWrite + "\"" + " " + "\"" + folderPath + "\"";
MyProcess.Start();
MyProcess.WaitForExit();
此代码生成TestFolder的jack.rar文件(所有子文件夹和文件)位于D:\。
现在我需要指定文件扩展名来创建该文件夹的.rar文件。
任何人都可以告诉我怎么能这样做。
This code makes an jack.rar file of TestFolder (All child folders and files) located in D:\.
Now i need to specify extensions of files for creating .rar file of that folder.
Can any one tell me how can i do that.
推荐答案
你可以在创建zip文件时添加一个额外的参数来提及文件的扩展名,你需要添加到你的zip文件中
You can add an extra parameter while creating the zip files to mention the extension of files , you need to add to your zip file
string zipFileToWrite, folderPath, pathExtensions;
zipFileToWrite = @"D:\jack.rar";
folderPath = @"D:\TestFolder";
pathExtensions = "*.txt";
System.Diagnostics.Process MyProcess = new System.Diagnostics.Process();
MyProcess.StartInfo.WorkingDirectory = @"D:\NetworkPathChecking\FileBackup\FileBackup\bin\Debug\App_Files\";
MyProcess.StartInfo.FileName = "winrar.exe";
MyProcess.StartInfo.Arguments = "a -r " + "\"" + zipFileToWrite + "\"" + " " + "\"" + pathExtensions + "\"" + " " + "\"" + folderPath + "\"";
MyProcess.StartInfo.Arguments = "a -r " + "\"" + zipFileToWrite + "\"" + " " + "\"" + folderPath + "\"";
MyProcess.Start();
MyProcess.WaitForExit();
请查看链接了解详情
< a href =http://comptb.cects.com/2503-using-the-winrar-command-line-tools-in-windows> http://comptb.cects.com/2503-using-the-winrar -command-line-tools-in-windows [ ^ ]
希望它有助于
[快乐编码]
Please check the link for details
http://comptb.cects.com/2503-using-the-winrar-command-line-tools-in-windows[^]
Hope it Helps
[ Happy coding ]
Hello Rakesh,
有两种方法可以达到这个目的
Hello Rakesh,
There are two ways you can achieve this
- 将多个扩展名指定为* .asp * .gif * .css作为命令行的一部分用空格字符分隔
- 使用外部文件其中每个扩展名在单独的行中提及。然后在命令行上将此文件名指定为
@ file_list.lst
问候,
Regards,
我通过添加文件列表作为命令参数解决了这个问题。
我的代码
I were solved this problem by adding list of file as command argument.
My Code
public static string RarFilesT(string rarPackagePath, Dictionary<int,> accFiles)
{
string error = "";
try
{
string[] files = new string[accFiles.Count];
int i = 0;
foreach (var fList_item in accFiles)
{
files[i] = "\"" + fList_item.Value;
i++;
}
string fileList = string.Join("\" ", files);
fileList += "\"";
System.Diagnostics.ProcessStartInfo sdp = new System.Diagnostics.ProcessStartInfo();
string cmdArgs = string.Format("A {0} {1} -ep1 -r",
String.Format("\"{0}\"", rarPackagePath),
fileList);
sdp.ErrorDialog = true;
sdp.UseShellExecute = true;
sdp.Arguments = cmdArgs;
sdp.FileName = rarPath;//Winrar.exe path
sdp.CreateNoWindow = false;
sdp.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
System.Diagnostics.Process process = System.Diagnostics.Process.Start(sdp);
process.WaitForExit();
error = "OK";
}
catch (Exception ex)
{
error = ex.Message;
}
return error;
}
private void btnSave_Click(object sender, EventArgs e)
{
Dictionary<int,> accFiles = new Dictionary<int,>();
accFiles.Add(1, @"D:\New folder\New folder\*.txt");
accFiles.Add(2, @"D:\New folder\*.html");
RarFilesT(@"D:\test.rar",accFiles );
}
这篇关于如何指定多个文件扩展名来制作文件夹的rar?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!