简体   繁体   中英

Reading special characters from filename into variable

I have thousands of files whose filenames contain the "caret" symbol, but when I try to assign them to a variable, I get weird results. If the filename is "01 ^ Driver's Seat.flac," for example, the command echo %1 returns "(path)\\01 ^^ Driver's Seat.flac," with an extra caret, and processing halts. How to I get the correct output?

Doubling of carets is a problem of the CALL command (see: How the batch parser works ).

This can be avoided by using calling a function with variables by reference instead of variables by value.

call :func "%variableName%" -- by value
call :func variableName -- by reference

call :func filename

...

:func
setlocal EnableDelayedExpansion
set "filename=!%1!"
echo filename: !filename!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM