问题描述
我有一组基本文件名,对于每个名字'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:
- 显示基础name'f'
- 对'f.in'执行操作
- 对'f.out'执行另一个操作
我没有办法列出基本文件名的集合,除了搜索* .in(或* .out)例如。 / p>
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扩展为文件名。
请参阅(页面中间)或刚才下一个答案。
%%~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.
这篇关于如何在批处理文件中循环匹配通配符的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!