日期:2014-05-18 浏览次数:20860 次
//添加引用Shell32.dll 在系统文件夹里 public bool BuildFrame(string srcFile, string destFolder) { try { Shell32.ShellClass sc = new Shell32.ShellClass(); Shell32.Folder SrcFolder = sc.NameSpace(srcFile); Shell32.Folder DestFolder = sc.NameSpace(destFolder); Shell32.FolderItems items = SrcFolder.Items(); DestFolder.CopyHere(items, 20); return true; } catch { return false; } }
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using ICSharpCode.SharpZipLib.Zip;
namespace Microsoft.ITF.Tools.GZIP
{
public class GZip
{
/// <summary>
/// 打包文件
/// </summary>
/// <param name="filenames">要打包的文件列表 </param>
/// <param name="GzipFileName">目标文件名 </param>
/// <param name="CompressionLevel">压缩品质级别(0~9) </param>
/// <param name="SleepTimer">休眠时间(单位毫秒) </param>
public static void DoZip( List <FileInfo> filenames, string GzipFileName, int CompressionLevel, int SleepTimer )
{
ZipOutputStream s = new ZipOutputStream( File.Create( GzipFileName ) );
try
{
s.SetLevel( CompressionLevel ); //0 - store only to 9 - means best compression
foreach ( FileInfo file in filenames )
{
FileStream fs = null;
try
{
fs = file.Open( FileMode.Open, FileAccess.ReadWrite );
}
catch
{ continue; }
byte[] buffer = new byte[fs.Length];
fs.Read( buffer, 0, buffer.Length );
ZipEntry entry = new ZipEntry( Path.GetFileName( file.Name ) );
entry.DateTime = ( file.CreationTime > file.LastWriteTime ? file.LastWriteTime : file.CreationTime );
s.PutNextEntry( entry );
s.Write( buffer, 0, buffer.Length );
fs.Close();
file.Delete();
if ( SleepTimer > 10 )
Thread.Sleep( SleepTimer );
}
}
finally
{
s.Finish();
s.Close();
}
}
/// <summary>
/// 打包文件
/// </summary>
/// <param name="filenames">要打包的文件列表 </param>
/// <param name="GzipFileName">目标文件名 </param>
/// <param name="CompressionLevel">压缩品质级别(0~9) </param>
/// <param name="SleepTimer">休眠时间(单位毫秒) </param>
public static void DoZip( List <string> filenames, string GzipFileName, int CompressionLevel, int SleepTimer )
{
ZipOutputStream s = new ZipOutputStream( File.Create( G