Batch file 不通过[batch]从变量创建标记
我想使用/作为分隔符从变量中提取标记。 我用这个::Batch file 不通过[batch]从变量创建标记,batch-file,cmd,Batch File,Cmd,我想使用/作为分隔符从变量中提取标记。 我用这个:: set fileinput=properties\iam\self_iam_properties.xml for /f "tokens=*delims=\" %%a in (%fileinput%) do @echo %%a 这给了我以下错误: The system cannot find the file properties\iam\self_iam_properties.xml. 为什么要搜索文件,我只需要使用变量中的值。我不想从
set fileinput=properties\iam\self_iam_properties.xml
for /f "tokens=*delims=\" %%a in (%fileinput%) do @echo %%a
这给了我以下错误:
The system cannot find the file properties\iam\self_iam_properties.xml.
为什么要搜索文件,我只需要使用变量中的值。我不想从文件中获取值
同样在解析之后,我希望创建一个名为self_iam_parsedoutput.txt的文件,以便从输入文件名中提取self_iam_u。如何继续?将%fileinput%放在双引号中,将其视为字符串
for /f "tokens=*delims=\" %%a in ("%fileinput%") do @echo %%a
请注意,因为您使用的是tokens=*,所以它实际上不会拆分为多个变量。如果希望路径的每个部分都有自己的变量,可以使用tokens=1-26之类的东西
在for/f中转义变量的第二种方法是运行输出变量的命令
for /f %a in ('echo.%variable%')
如果您在使用双引号时遇到问题,此表单非常有用
至于文件名更改,如果输入文件始终为xyz_properties.xml,输出文件始终为xyz_parsedoutput.txt,则可以使用简单的文本替换形式%variable:old=new%
同样在解析之后,我希望创建一个名为self_iam_parsedoutput.txt的文件,以便从输入文件名中提取self_iam_u。如何继续?更新为在变量中包含关于文本替换的位。
set inputfile=self_iam_properties.xml
set outputfile=%inputfile:properties.xml=parsedoutput.txt%