Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Grab list of files then pass filenames on the command line

Dec
48
1
Grab list of files then pass filenames on the command line -- preferably on the same command line!

Does anyone know of a convenient "coding metaphor" or pattern for doing the following?

Assume I have some external program, for example, a programmer's editor (let's call it "Ed" for convenience).
I can list a bunch of filenames on the command line following "Ed" and it will open those files or do whatever it does with them.
The program can't be passed anything like an "include list file" (single file containing paths to other files).

Now, suppose I want to build the list of files from some filter (or something like a FOR command) and then use it.
Let's assume that If I call the same program repeatedly, it will start separate instances, and I want a single instance, so I can't do something like the following:

> for /h /r %ff in (*something*.txt) do Ed "%ff"

I used to know how to do this! The best thing I can think of now, on short notice, is to build up an environment variable and use it, then drop it...

> unset flist & for /h /r %ff in (*something*.txt) do (set flist=%ff %flist ) & Ed %flist & unset flist

Any ideas?
 
How about Ed %@expand[*something*.txt]?

Yeah, I'd forgotten all about @EXPAND[], and this will handle the majority of cases!
Ugh, except at least one: the recursive descent example above.

I'll keep digging for an improved way of handling that one case, and I'll post it here for others (if someone else doesn't beat me to it!)

Vince, you've been so much help to me over the years. Thanks!!
 
you've been so much help to me over the years. Thanks!!


Thanks! I'm glad to hear that. If you want recursion, I think you're stuck with a loop and building an environment variable. I suppose you could combine GLOBAL and @EXPAND but I doubt that would be any better than your original approach.

Another approach would be a DIR /k /m /s /f file_spec > file_list.tmp (of FFIND similarly, neither of which will add any necessary quotes) and then DO line in @file_list (with @QUOTE) to build the variable.

Finally, if you think others would benefit, you could go to the "Suggestions" forum to suggest that @EXPAND be given an optional recurse_with_full_names option.
 
Back
Top