In my "Documents" folder I've created two directories with names "тест" and "тест 2". When I try to use RunProcess
for obtaining directory listing for the first directory it works as expected:
RunProcess[{"cmd", "/c", "\"dir /b \"D:\\Documents\\тест\"\""}]
<|"ExitCode" -> 0, "StandardOutput" -> "test file.txt ", "StandardError" -> ""|>
But for the second directory it fails telling that the file is not found:
RunProcess[{"cmd", "/c", "\"dir /b \"D:\\Documents\\тест 2\\\"\""}]
<|"ExitCode" -> 1, "StandardOutput" -> "", "StandardError" -> "Не удается найти указанный файл. "|>
It is interesting that the same happens when I remove the additional quotes around the directory path:
RunProcess[{"cmd", "/c", "\"dir /b D:\\Documents\\тест 2\\\""}]
<|"ExitCode" -> 1, "StandardOutput" -> "", "StandardError" -> "Не удается найти указанный файл. "|>
If I remove the ending backslash \\
, I get the directory listing for the directory "тест" (instead of "тест 2") and the "File Not Found" error:
RunProcess[{"cmd", "/c", "\"dir /b D:\\Documents\\тест 2\""}]
<|"ExitCode" -> 1, "StandardOutput" -> "test file.txt ", "StandardError" -> "Файл не найден "|>
Wrapping the directory path with quotes changes nothing:
RunProcess[{"cmd", "/c", "\"dir /b \"D:\\Documents\\тест 2\"\""}]
<|"ExitCode" -> 1, "StandardOutput" -> "test file.txt ", "StandardError" -> "Файл не найден "|>
It looks like the quotes are simply ignored...
Why is that? Is it a bug? Is there a workaround?
When I try the old Import
route everything works as expected:
Import["!dir /b \"D:\\Documents\\тест 2\\\"", "Text"]
"test file 2.txt"