Need help with custom command (mklink)

English support forum

Moderators: Hacker, petermad, Stefan2, white

User avatar
Dalai
Power Member
Power Member
Posts: 9945
Joined: 2005-01-28, 22:17 UTC
Location: Meiningen (Südthüringen)

Re: Need help with custom command (mklink)

Post by *Dalai »

2white
Wouldn't that also apply to %P%S?

Anyway, CMD and charsets and Unicode is an issue as old as CMD itself. There are multiple ways to deal with this:
  • Tell CMD to switch to Unicode via /U switch.
  • Use chcp 65001 at the script start to switch to UTF-8, but then it's more appropriate to use %UL instead of %WL for the list file.
BTW, the type command itself can read UTF-16 files just fine.
#101164 Personal licence
Ryzen 5 2600, 16 GiB RAM, ASUS Prime X370-A, Win7 x64

Plugins: Services2, Startups, CertificateInfo, SignatureInfo, LineBreakInfo - Download-Mirror
User avatar
white
Power Member
Power Member
Posts: 5747
Joined: 2003-11-19, 08:16 UTC
Location: Netherlands

Re: Need help with custom command (mklink)

Post by *white »

Dalai wrote: 2024-11-20, 20:48 UTC Wouldn't that also apply to %P%S?
No, because you would be using "For" then. The difference is between using "For" (which has good Unicode support) and "For /F" (file parsing, which does not have good Unicode support).
User avatar
Dalai
Power Member
Power Member
Posts: 9945
Joined: 2005-01-28, 22:17 UTC
Location: Meiningen (Südthüringen)

Re: Need help with custom command (mklink)

Post by *Dalai »

There are some minor differences in output between these two buttons:

Code: Select all

TOTALCMD#BAR#DATA
cmd /k
for /F "delims=" %%F IN ('type "%WL"') DO echo %%F
shell32.dll
For File


-1

Code: Select all

TOTALCMD#BAR#DATA
cmd /k
for %%F IN (%P%S) DO echo %%F
shell32.dll
For %P%S


-1
The former passes a trailing backslash to each directory name and the latter quotes every path. But when it comes to characters there's no difference that I can see. Both of them properly show umlauts, both of them can't show Cyrillic or Asian characters (might be due to the font used in CMD).

Umlauts are NOT properly shown when using %L instead of %WL, even if CMD is called with the /U switch. That's another reason why I use the type command which has no problem with UTF-16 files as I already mentioned above. This way it's not the loop reading the file (which doesn't seem to support UTF-16 files) but the type command.
#101164 Personal licence
Ryzen 5 2600, 16 GiB RAM, ASUS Prime X370-A, Win7 x64

Plugins: Services2, Startups, CertificateInfo, SignatureInfo, LineBreakInfo - Download-Mirror
User avatar
white
Power Member
Power Member
Posts: 5747
Joined: 2003-11-19, 08:16 UTC
Location: Netherlands

Re: Need help with custom command (mklink)

Post by *white »

Dalai wrote: 2024-11-20, 21:55 UTC Umlauts are NOT properly shown when using %L instead of %WL, even if CMD is called with the /U switch. That's another reason why I use the type command which has no problem with UTF-16 files as I already mentioned above.
But type converts to current codepage, does it not? So it works if your current codepage contains umlaut characters, but I thought in general you need to use chcp 65001 (which is a pain).
User avatar
Dalai
Power Member
Power Member
Posts: 9945
Joined: 2005-01-28, 22:17 UTC
Location: Meiningen (Südthüringen)

Re: Need help with custom command (mklink)

Post by *Dalai »

white wrote: 2024-11-21, 00:05 UTCBut type converts to current codepage, does it not?
I can't remember the last time I had to process filenames with characters from other codepages in a batch script, or if I ever did that, so I honestly don't know.
[...] but I thought in general you need to use chcp 65001 (which is a pain).
True.

Here's the conclusion I draw from the discussion: If you don't need to worry about Unicode characters or from other codepages, the approach shown by 3axarko is likely sufficient and works out of the box since it makes use of the tools available in Windows (at least since Vista). However, external tools like NTFS Links or NTLinks Maker can properly handle Unicode and it's probably better to use them if one has to process such files on a regular basis. It's not that hard to include them even in a portable TC either.
#101164 Personal licence
Ryzen 5 2600, 16 GiB RAM, ASUS Prime X370-A, Win7 x64

Plugins: Services2, Startups, CertificateInfo, SignatureInfo, LineBreakInfo - Download-Mirror
Post Reply