0

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

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"

(Actually the folder method would probably be better since I could make a drag-and-drop shortcut or SendTo menu item.)

endolith
  • 25,479
  • 34
  • 128
  • 192
  • 1
    Inside your batch file, use the `FOR` command to get a list of files within a folder. – Squashman Jul 12 '17 at 16:30
  • @Squashman I've read many related questions and answers on here, but I can't figure out how to produce a single-line list of filenames and pass the whole list to a command as the argument – endolith Jul 12 '17 at 16:35

1 Answers1

1

This kind of works, based on 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
endolith
  • 25,479
  • 34
  • 128
  • 192