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

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

问题描述

我有一组基本文件名,对于每个名称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"执行另一个操作

我没有任何方法可以列出一组基本文件名,只能搜索 *.in(或 *.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 扩展为文件名.请参阅 https://technet.microsoft.com/en-us/library 中的其他修饰符/bb490909.aspx(页面中间)或就在下一个答案中.

%%~nf is a substitution modifier, that expands %f to a file name only. See other modifiers in https://technet.microsoft.com/en-us/library/bb490909.aspx (midway down the page) or just in the next answer.

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

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