【问题标题】:Iterate through text file with batch file使用批处理文件遍历文本文件
【发布时间】:2015-04-22 02:57:29
【问题描述】:

我想知道如何使用 Windows 批处理文件循环遍历文本文件中的每一行并连续处理每一行文本。我有一个包含文件名的文本文件。

我想做的是像

for x in textFile
    "python C:\main.py -s x"  # the command i want to run

【问题讨论】:

标签: loops batch-file dos


【解决方案1】:
for /f %%x in (textFilename) do python C:\main.py -s %%x

将是经典方法 - 作为批处理文件。

如果您直接从提示符运行,请将 %% 减少到 %

或者,更全面地说,

for /f "usebackqdelims=" %%x in ("textFilename") do python C:\main.py -s "%%x"

【讨论】:

  • 不要忘记包含"delims=" 以获取整行,以及"usebackq" 以防文件路径在某处有空格。
猜你喜欢
  • 2011-01-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-09-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-28
相关资源
最近更新 更多