如何通过批处理文件通配符匹配的文件循环 [英] How to loop through files matching wildcard in batch file

查看:165
本文介绍了如何通过批处理文件通配符匹配的文件循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组基地的文件名,每个名字'F'恰好有两个文件,​​f.in'和'f.out。我想写这遍历所有文件名的批处理文件(在Windows XP),为每一个它应该:

I have a set of base filenames, for each name 'f' there are exactly two files, 'f.in' and 'f.out'. I want to write a batch file (in Windows XP) which goes through all the filenames, for each one it should:


  • 显示基本名称'F'

  • 执行上'f.in
  • 动作
  • 执行上'f.out
  • 其他操作
  • Display the base name 'f'
  • Perform an action on 'f.in'
  • Perform another action on 'f.out'

我没有任何办法列出组基本的文件名,除了搜索*。在(或* .OUT)为例。

I don't have any way to list the set of base filenames, other than to search for *.in (or *.out) for example.

推荐答案

假设你有两个程序处理两个文件,​​process_in.exe和process_out.exe:

Assuming you have two programs that process the two files, process_in.exe and process_out.exe:

    for %%f in (*.in) do (

            echo %%~nf
            process_in "%%~nf.in"
            process_out "%%~nf.out"
    )

%%〜NF是一种替代修改,使得f只有一个文件名扩展%。
请参阅<一个其他修饰符href=\"https://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/batch.mspx?mfr=true\">https://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/batch.mspx?mfr=true (中途下页),或只是在未来的答案。

%%~nf is a substitution modifier, that expands %f to a file name only. See other modifiers in https://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/batch.mspx?mfr=true (midway down the page) or just in the next answer.

这篇关于如何通过批处理文件通配符匹配的文件循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆