在Windows中将多个通配符文件名传递给命令 [英] Passing multiple wildcard filenames to a command in Windows
问题描述
现在在Windows上使用gcc进行开发的过程中,我两次遇到 perl 脚本适用于以> 100个文件名列表作为参数的Unix系统,我需要使用通配符来创建,以从许多其他文件的文件夹中选择通配符:
Twice now during development with gcc on Windows, I've run into perl scripts meant for Unix systems that take a list of >100 filenames as their argument, which I need to create using wildcards to select them out of a folder of many other files:
perl avstack.pl */*.o
perl egypt *.expand
但是Windows不会进行通配符扩展,因此命令本身是必需的.如何编写批处理脚本以获取文件名列表并将其传递给程序?例如:
But Windows doesn't do wildcard expansion, the command itself is required to do this. How can I write a batch script to get the list of filenames and pass it to the program? For example:
avstack.bat */*.o
egypt.bat *.expand
或者,由于每个批处理文件都知道文件扩展名,因此可以使用文件夹名称来调用它:
Or, since the file extensions are known for each batch file, it could be called with a folder name instead:
avstack.bat "C:\path\with\some_o_files"
egypt.bat "D:\path\with\some_expand_files"
(实际上,文件夹方法可能会更好,因为我可以创建拖放快捷方式或SendTo菜单项.)
(Actually the folder method would probably be better since I could make a drag-and-drop shortcut or SendTo menu item.)
推荐答案
此类作品基于 https://superuser. com/a/460648/13889 :
@echo off
cd "%~1"
set expanded_list=
for %%f in (*.expand) do call set expanded_list=%%expanded_list%% "%%f"
perl egypt %expanded_list% > egypt-output.txt
这篇关于在Windows中将多个通配符文件名传递给命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!