How to safely append a file name to a Windows folder path argument?

后端 未结 3 823
無奈伤痛
無奈伤痛 2020-12-31 21:26

Suppose I have a batch script that expects a folder path in argument %1. I want to append a file name to the path and use that in a command. Is there a simple w

3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2020-12-31 21:28

    Since ~f eliminates multiple backslashes, I think this works just as well as the original proposal, and also appears to handle share roots and long paths correctly:

    for /F "delims=" %%i in (%~f1\file.ext) do set filename=%%~fi
    

提交回复
热议问题