Skip to content

Commit a3fce05

Browse files
authored
Merge pull request #89 from wcogan/utf8-path-support
Added support for handling file paths as UTF8
2 parents f9aa53c + 3a08204 commit a3fce05

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

WindowsApp1/Compact.vb

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ Public Class Compact
272272

273273
Dim DIwDString = New DirectoryInfo(wDString)
274274
directorysizeexceptionCount = 0
275-
workingDir = Chr(34) + wDString.ToString() + Chr(34)
275+
workingDir = wDString.ToString()
276276
chosenDirDisplay.Text = DIwDString.Parent.ToString + " ❯ " + DIwDString.Name.ToString
277277
uncompressedfoldersize = Math.Round(DirectorySize(DIwDString, True), 0)
278278
preSize.Text = "Uncompressed Size: " + GetOutputSize _
@@ -346,6 +346,9 @@ Public Class Compact
346346
With MyProcess.StartInfo
347347
.FileName = "CMD.exe"
348348
.Arguments = ""
349+
.StandardOutputEncoding = Encoding.UTF8 'Allow console output to use UTF-8. Otherwise it will translate to ASCII equivalents.
350+
.StandardErrorEncoding = Encoding.UTF8
351+
.WorkingDirectory = workingDir 'Set working directory via argument, allows UTF-8 to be passed directly.
349352
.UseShellExecute = False
350353
.CreateNoWindow = True
351354
.RedirectStandardInput = True
@@ -359,16 +362,8 @@ Public Class Compact
359362
MyProcess.BeginErrorReadLine()
360363
MyProcess.BeginOutputReadLine()
361364

362-
363365
Try
364-
365-
MyProcess.StandardInput.WriteLine("cd /d " + workingDir)
366-
MyProcess.StandardInput.Flush()
367-
368-
MyProcess.StandardInput.WriteLine("") 'Required for the embedded console to show the next line in the buffer after the 'cd' command. No idea why
369-
MyProcess.StandardInput.Flush()
370-
371-
MyProcess.StandardInput.WriteLine("chcp 437")
366+
MyProcess.StandardInput.WriteLine("chcp 65001") 'UTF-8 codepage in console output. Otherwise it will translate to ASCII equivalents.
372367
MyProcess.StandardInput.Flush()
373368

374369
RunCompact(passthrougharg)

0 commit comments

Comments
 (0)