David8988
David8988

Reputation: 79

Why cmd cannot read paths that contain words in a language different from English?

I have this batch script for copying between two folders:

xcopy /y "C:\Users\_____\workspace" "D:\Backup_for_project"
pause  

Where the empty line there: ____ is my name in a langauge different from English.
The cmd doesn't recognize this and I get an error that path doesn't exsits.

My script works if the words in the path are in English only.

How can I fix it so that the cmd will also recognize this specific word?

Upvotes: 0

Views: 319

Answers (2)

lit
lit

Reputation: 16236

I would be interested to know if this works for you.

powershell -NoProfile -Command Copy-Item -Path "$Env:USERPROFILE/workspace" -Destination "D:\Backup_for_project" -Recurse

Upvotes: 0

user6811411
user6811411

Reputation:

IMO using %USERPROFILE% is the easier way, but to follow eryksun's hints:

@Echo off

:: to be language independent I use two For /F first split : 
:: then trim spacce and possible . (in German for example)
For /F "tokens=2 delims=:" %%A in ('chcp'
) Do For /F "delims=. " %%B in ("%%A") Do set "CP_Current=%%B"

:: to remove UTF16 conversion remnants (cr,cr,lf) of wmic
:: here also a double for is required
For /F %%A in ('wmic os get codeset /value^|find "="'
) Do For /F %%B in ("%%A") Do Set %%B

:: Switch codepage
Echo Switching to codepage %CodeSet%
chcp %CodeSet%

Echo do whatever you like with codepage %CodeSet%
Timeout /T 10

:: Switch back to saved codepage
Echo Switching back to codepage %CP_Current%
chcp %CP_Current%
Timeout /T 10

Upvotes: 1

Related Questions