Skip to content

Instantly share code, notes, and snippets.

@devlights
Created June 5, 2013 02:57
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devlights/5711309 to your computer and use it in GitHub Desktop.
Save devlights/5711309 to your computer and use it in GitHub Desktop.
System.IO.Compression.ZipFileクラスにて、日本語のディレクトリ名やファイル名を文字化けさせずに圧縮処理
namespace Sazare.Samples
{
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Text;
using Sazare.Common;
public class ZipFileSamples04 : IExecutable
{
public void Execute()
{
//
// sourcePathのディレクトリ構造は以下のようになっている。
//
// [構造]
// 日本語フォルダ (ディレクトリ)
// --> あいうえお (ディレクトリ)
// --> 日本語ファイル名.txt (テキストファイル)
//
const string sourcePath = @"D:\Temp\日本語フォルダ";
const string destPath = @"日本語ファイル名.zip";
if (File.Exists(destPath))
{
File.Delete(destPath);
}
//
// フォルダ毎圧縮.
//
ZipFile.CreateFromDirectory(sourcePath, destPath, CompressionLevel.Optimal, true, Encoding.GetEncoding("sjis"));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment