Windows 10 Pro version 21H2 OS build 19044.2604
I entered this command:
for /d %X in (dv*) do echo %X
and the result was
Dvorák, Antonin (1841-1904)
except with an upside-down caret over the r. That's identical to what
File Explorer shows.
Then I redirected the output to a batch file:
for /d %X in (dv*) do echo cd %X >foo.bat
I executed foo in the same command window and got "The system cannot
find the path specified." I then entered
type foo.bat
and the response was
cd Dvorák, Antonin (1841-1904)
with _no_ accent mark on the r.
chcp tells me that the active code page is 437, for what relevance
that may have. I could understand if the r-with-upside-down-caret
didn't display in the command window, since CP437 doesn't include it <https://en.wikipedia.org/wiki/Code_page_437>. But it did display
there, only was changed to a regular r in redirection.
Can someone explain what's going on here? Thanks!
Thanks, Vanguard, for taking as much trouble as you did. I'm terribly
sorry -- I do know about quoting filenames or paths that contain
spaces, but I had been messing around with this all afternoon,
getting more and more frustrated, and when I finally decided to post,
in trying to simplify things I got careless. I apologize!
I don't actually use cmd.exe very much -- I've been using TCC or
TCCLE from JPsoft for decades. But I posted all of my examples using
cmd not TCCLE -- to make sure some quirk in TCCLE wasn't responsible.
error. And I copy/pasted from the cmd.exe window, not retyping
anything.
Yes, it's an NTFS partition (d:). I believe that the name as
displayed in File Explorer is indeed Unicode, since the r-upside-
down-caret is not in characters 0-255 of the Windows character set
1252 or the older dos set 437. (I looked at a character table of each
one, and didn't see it. That doesn't necessarily mean it's not there,
but I sure didn't see it.)
So let me do it right this time:
Typing
for /d %X in (dv*) do echo cd "%X"
on the command line displays
cd "Dvorák, Antonin (1841-1904)"
but the /r/ has an upside-down caret on it.
That's cd "%X" not cd "%X%" -- when I tried the latter on the command
line I got
cd "Dvorák, Antonin (1841-1904)%"
i.e., an extra % after the directory name. I'm guessing that the
variable named in the for command is special in this regard.
for /d %X in (dv*) do echo cd "%X" >foo.bat
displays
echo cd "Dvorák, Antonin (1841-1904)" 1>foo.bat
_with_ the upside-down-careted /r/
and the command "type foo.bat" displays
cd "Dvorák, Antonin (1841-1904)"
with no caret on the /r/. Executing /foo/ displays
cd "Dvorák, Antonin (1841-1904)"
The system cannot find the path specified.
(with no caret on the /r/).
I do understand when I go to put the for command in a batch file, it
will have to use "for %%x" etc., but I'm trying to solve this by
divide and conquer.
However, now that you've set me straight on 8.3 shortnames in my
other thread, I think that's really the answer. Shortnames won't use
special characters or contain spaces, so they shouldn't pose a
problem for robocopy. And my car doesn't care how the folders on the
USB stick are named, so I can just use the shortnames as the _only_
folder names on my USB stick's exFAT volume. (The car doesn't
recognize NTFS formatting, which is no surprise.)
Ah, looks like I found the problem. The command shell defaults to the
437 code page. You need to change to the 65001 code page for UTF-8
support. Run:
chcp 65001
echo "dvorák" > testme.bat
type testme.bat
"dvorák"
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 297 |
Nodes: | 16 (2 / 14) |
Uptime: | 06:13:53 |
Calls: | 6,666 |
Files: | 12,213 |
Messages: | 5,336,023 |