从批处理文件中的.txt文件读取多个路径

问题描述 投票:0回答:1

我有一个批处理脚本,它需要读取config.txt中提到的多个目录路径。我可以为配置文件中提到的一个目录路径实现相同的功能,但相同版本的修改版本不适用于多个路径。

下面是运行良好的示例。

@echo off
for /F "usebackq delims=" %%L in (config.txt) do set "DataPath=%%L"
set "DataPath=%DataPath:/=\%"
echo Application path is: %DataPath%

请建议对多个目录路径进行相同的修改。感谢advnc

EDIT:下面是我尝试获取两个路径,并且'%DataPath%'正在打印该值。

@echo off
for /F "usebackq tokens=1,2 delims=" %%L in (config.txt) do set 
"DataPath=%%L"&set "filepath=%%M"
 set "DataPath=%DataPath:/=\%"
 set "filepath=%filepath:/=\%"
 echo Application path is: %DataPath%
 echo Application path is: %filepath%
windows batch-file filepath
1个回答
0
投票

根据我在评论中给出的建议,您在编辑中没有实现,下面的方法是我希望您想到的:

@Echo Off
SetLocal DisableDelayedExpansion
For /F "UseBackQ Delims=" %%L In ("config.txt") Do (
    Set "DataPath=%%L"
    SetLocal EnableDelayedExpansion
    Set "DataPath=!DataPath:/=\!"
    Echo Application path is: !DataPath!
    EndLocal
)
Pause

这假设config.txt包含一个仅文件路径的列表,每行一个。

© www.soinside.com 2019 - 2024. All rights reserved.