解凍時の文字化けは、ZIPファイルのヘッダか、解凍ソフトのどちらかに問題があると思われます。ZIPのヘッダには、utf-8を使用しているかのビットフラグが存在し、そこを見て解凍ソフト側が文字コード処理を切り替えるように実装しているかどうかです。7-Zip辺りは、Shift_JISでファイル名を突っ込んでも、そのビットがOFFなら正しいファイル名で解凍してくれると思いますが。
割と根が深い問題なので、ヘッダをアテにせず、独自に文字コード判定を行っている解凍ソフトもあります。
考えられる解決策としては、
何とかしてPowerShellにファイル名を渡す(PowerShellのスクリプトファイルを出力して実行するとか?)
エンコードせずにpowershellコマンドに渡して、文字化けしない事を確認しました。(Windows10)
Compress-Archiveの代替手段を探す
出力されたZIPを何らかの手段で修復・変換する
(ヘッダがおかしいか、ファイル名がおかしいかを特定する必要あり)
こんなもんでしょうか。
これで解消!「KB2704299」でCompress-Archiveの文字化け対処
こんな記事がありましたが、上記環境に該当してないですか?
こちらで動作確認したコードを載せておきます。日本語のフォルダ名やファイル名でも、特に問題ありませんでした。
[2021/09/15 15:51]
Shift_JISファイル名のZIP出力処理を追記しました。
vba
1 Option Explicit
2
3 Private Declare PtrSafe Function ShellExecuteW Lib "shell32.dll" ( _
4 ByVal hwnd As LongPtr , _
5 ByVal lpOperation As LongPtr , _
6 ByVal lpFile As LongPtr , _
7 ByVal lpParameters As LongPtr , _
8 ByVal lpDirectory As LongPtr , _
9 ByVal nShowCmd As Long _
10 ) As LongPtr
11
12 Private Declare PtrSafe Sub Sleep Lib "kernel32" ( ByVal ms As Long )
13
14 Const SW_HIDE = 0 'ウィンドウを表示しない
15 Const SW_SHOW = 5 'ウィンドウを現在の位置とサイズで表示
16
17 Private Sub CommandButton1_Click ( )
18 Dim src As String
19 src = "c:\test\あいうえお"
20
21 Call CreateZipWsh ( src , "c:\test\test_wsh.zip" )
22 Call CreateZipShellExecuteW ( src , "c:\test\test_shellw.zip" )
23 Call CreateZipShellExecuteW_SJIS ( src , "c:\test\test_shellw_sjis.zip" )
24 End Sub
25
26 'WScript.Shellで実行
27 Private Sub CreateZipWsh ( ByVal src As String , ByVal dest As String )
28 Dim parameter As String
29 Dim oWsh As Object
30 Dim oExec As Object
31
32 parameter = "-NoLogo -ExecutionPolicy RemoteSigned -Command Compress-Archive -Path '" & src & "' -DestinationPath '" & dest & "' -Force"
33 Set oWsh = CreateObject ( "WScript.Shell" )
34 Set oExec = oWsh . Exec ( "powershell.exe" & " " & parameter )
35 Do While oExec . Status = 0
36 Sleep 1
37 Loop
38 Set oExec = Nothing
39 Set oWsh = Nothing
40 End Sub
41
42 'ShellExecuteWで実行
43 Private Sub CreateZipShellExecuteW ( ByVal src As String , ByVal dest As String )
44 Dim exe As String
45 Dim operation As String
46 Dim parameter As String
47
48 operation = "open"
49 exe = "powershell.exe"
50 parameter = "-NoLogo -ExecutionPolicy RemoteSigned -Command Compress-Archive -Path '" & src & "' -DestinationPath '" & dest & "' -Force"
51 Call ShellExecuteW ( 0 , StrPtr ( operation ) , StrPtr ( exe ) , StrPtr ( parameter ) , 0 , SW_HIDE )
52 End Sub
53
54 'ShellExecuteWで実行(Shift_JIS出力)
55 Private Sub CreateZipShellExecuteW_SJIS ( ByVal src As String , ByVal dest As String )
56 Dim exe As String
57 Dim operation As String
58 Dim cmd As String
59 Dim parameter As String
60
61 operation = "open"
62 exe = "powershell.exe"
63 cmd = "Add-Type -AssemblyName System.IO.Compression.FileSystem;"
64 cmd = cmd & "[IO.Compression.ZipFile]::CreateFromDirectory('" & src & "', '" & dest & "', [IO.Compression.CompressionLevel]::Optimal, $true, [Text.Encoding]::GetEncoding('Shift_JIS'));"
65 parameter = "-NoLogo -ExecutionPolicy RemoteSigned -Command " & cmd
66 Call ShellExecuteW ( 0 , StrPtr ( operation ) , StrPtr ( exe ) , StrPtr ( parameter ) , 0 , SW_HIDE )
67 End Sub