Escape special character in a windows batch

前端 未结 2 1019
陌清茗
陌清茗 2021-01-23 20:06

I have a batch file that receive a path as first argument. The path is always composed with specials characters like ^,é or è.

The

2条回答
  •  情歌与酒
    2021-01-23 20:22

    You need to escape the caret signs at the command line or better put the path into quotes.

    In both cases you should work with delayed expansion, as then the content will not be modified when it is expanded.

    myBatch "C:\LASTNAME^Firstname\image"
    

    or

    myBatch C:\LASTNAME^^Firstname\image
    

    And in your batch use swomething like this

    @echo off
    set "arg1=%~1"
    setlocal EnableDelayedExpansion
    echo !arg1!
    

提交回复
热议问题