7-ZIP32.DLLを使用しフォルダごと圧縮するその2
7-ZIP32.DLLをC#で利用する
パスがロングネームだと失敗するときがあるのでショートネームにしている
[DllImport("7-zip32.dll", CharSet = CharSet.Ansi)] private extern static int SevenZip(IntPtr hWnd, string strCommandLine, StringBuilder strOutPut, uint outputSize); [DllImport("kernel32.dll")] static extern uint GetShortPathName(string strLongPath, StringBuilder strShortPath, uint buf); private void compressBtn_Click(object sender, EventArgs e) { string strInstancePath = Path.GetDirectoryName(Application.ExecutablePath) + "\\"; string strTargetFolderPath = strInstancePath; string strLogFolderPath = strInstancePath + "log\\"; IntPtr hWnd = this.Handle; StringBuilder strShortPath = new StringBuilder(1024); GetShortPathName(strTargetFolderPath, strShortPath, 1024); strTargetFolderPath = strShortPath.ToString(); GetShortPathName(strLogFolderPath, strShortPath, 1024); strLogFolderPath = strShortPath.ToString(); string strCommandLine = "a -tzip " + strTargetFolderPath + "test.zip " + strLogFolderPath + " *"; StringBuilder strOutPut = new StringBuilder(1024); int ret = SevenZip(hWnd, strCommandLine, strOutPut, 1024); }