I have been thinking this to death. Maybe one of you has an answer. I have a tool that extracts data from files of type A and writes it to files of type B. The user supplies file names and a "prefix" value that is used in the generatoin of the B files. The prefix goes
inside the file as part of the data. The rules are:
- If the input filename has no metacharacters (xxx.A) it is read and processed and the output file is generated. If no output file was specified use xxx.B.
- If the input filename has metacharacters, expand it (with glob) to generate a list of input files to process. If no output filename was specified apply the rule in step 1. (So if I have xx1-1.A and xx1-2.A, xx1-?.A processes those and generates xx1-1.B and xx1-2.B). Also, the user may want the output files to be xx1-data-1.B and xx1-data-2.B. I have to assume regular output filenames.
- If in either of the above cases an output file is specified, put all the output in that file.
- If a prefix was specified, use it to prefix the data in the output file. The trick is that the prefix needs to vary with the input filename, so if I have xx1-1.A and xx1-2.A the user needs to identify that the prefix for the first file is the 1 and the prefix for the second file is the 2.
Yes, this is an algorithm and human factors problem, but I am stuck. Right now I have a GUI with three entry windows: source, destination and prefix. I can handle a single input file and a single output file no problem. I can glob the filenames (this is in Windows) no problem. What I cannot seem to do is figure out how to specify the changing prefix, and how to specify the output file names. And of course, how to code the crazy thing...
I've tried specifying the input as xx1-{?}.A and parsing out the question mark and using it in the output file names, but I couldn't find a good way to generate them. I have the input filenames in an array (@src).
Any ideas about what I should do? --traveler