0

I'm using below macro in goal of obtaining list of all files in folder :

Sub SO()

Const parentFolder As String = "C:\Users\bloggsj\folder\" '// change as required, keep trailing slash

Dim results As String

results = CreateObject("WScript.Shell").Exec("CMD /C DIR """ & parentFolder & "*.*"" /S /B /A:-D").StdOut.ReadAll

Debug.Print results

Ens Sub

but it gives me invalid output as it doesn't chandle Unicode characters, which are part of files names in my directory. In normal batch file I could use additional command 'CHCP 1250' to change coding page for symbols. But I can't incorpotrate it into above macro. I've tried in several ways like :

results = CreateObject("WScript.Shell").Exec("CMD /C CHCP 1250 DIR """ & parentFolder & "*.*"" /S /B /A:-D").StdOut.ReadAll

and

results = CreateObject("WScript.Shell").Exec("CMD /C ""CHCP 1250"" ""DIR """ & parentFolder & "*.*"" /S /B /A:-D""").StdOut.ReadAll
Qbik
  • 5,885
  • 14
  • 62
  • 93

1 Answers1

1

Ampersand

command1 & command2 : Use to separate multiple commands on one command line. Cmd.exe runs the first command, and then the second command.

CMD /C CHCP 1250 & DIR ....

However VBA has native support for a directory listing and VBScript can use the FileSystemObject to achieve the same.

Community
  • 1
  • 1
Alex K.
  • 171,639
  • 30
  • 264
  • 288