【发布时间】:2014-07-18 15:53:19
【问题描述】:
我正在做这个项目,我从网上下载了我的 zip 文件,然后我会以编程方式解压缩它,然后将解压缩文件保存到特定文件夹。
例如,我要下载的 zip 文件包含 .png、.jpg、.docx、.ppt 文件。
所以我要做的是将所有 .png 保存到 PNG 文件夹中,将 .jpg 保存到 JPG 文件夹等中。
我已经完成了下载部分和解压缩。
现在的问题是如何根据文件类型将解压缩文件保存到不同的文件夹中?
谁能帮帮我。
至于现在这里是我制作的代码。
using System;
using Microsoft.Office.Interop.Excel;
using Excel = Microsoft.Office.Interop.Excel;
using System.Reflection;
using System.Net;
using System.ComponentModel;
namespace UnzipFile
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : System.Windows.Window
{
public MainWindow()
{
InitializeComponent();
}
这里是解压文件。
public static void UnZip(string zipFile, string folderPath)
{
if (!File.Exists(zipFile))
throw new FileNotFoundException();
if (!Directory.Exists(folderPath))
Directory.CreateDirectory(folderPath);
Shell32.Shell objShell = new Shell32.Shell();
Shell32.Folder destinationFolder = objShell.NameSpace(folderPath);
Shell32.Folder sourceFile = objShell.NameSpace(zipFile);
foreach (var file in sourceFile.Items())
{
destinationFolder.CopyHere(file, 4 | 16);
}
}
这里是解压文件,但保存在一个文件夹中。 zip 文件中的所有文件。
private void btnUnzip_Click(object sender, RoutedEventArgs e)
{
UnZip(@"E:\Libraries\Pictures\EWB FileDownloader.zip", @"E:\Libraries\Pictures\sample");
}
}
}
我想将提取的内容保存在不同的文件夹中。
【问题讨论】:
-
发布您目前拥有的内容,并尝试将其保存到单独的文件夹中。