-2

I have a couple lines of code in a batch file in Windows 10 that open a session of Octave, and load a script that uses design parameters contained in a .txt file. The batch file is named (for example) "Design123.bat", and when Octave runs, it automatically finds the design parameters in the file "Design123.txt" by simple string manipulation of the file name, i.e. strrep(filename,".bat",".txt"), where filename = '%~dpn0' is passed to Octave from the batch file. This allows for the contents of the batch file to stay simple and constant, and the file name of the batch file is the only thing tying it to the .txt file.

I do all of this to allow running the Octave script by double-clicking the batch file for convenience, instead of being forced to use the more tedious process of uigetfile in Octave. This works very well, but the catch is that I have to place a copy of the batch file in the same directory with the design (.txt) files (of which there are thousands, but each within their own directory) and give it the same file name to get it to work. Is there a way to quickly create the batch files somehow? The most ideal situation I can think of is to be able to right-click (or somehow select) a .txt design file, and create a batch file (replacing .txt with .bat) and place my lines of code into it.

Any ideas? I have coding experience, but only in software packages like VBA and Octave, not within operating systems themselves, though certainly willing to learn if I could get pointed in the right direction. The design file names follow a distinctive pattern, so they could be filtered easily within an operation on the active "File Explorer" window in Windows 10, if something like that is possible. Thanks in advance.

smcmi
  • 106
  • 8
  • I would certainly do this all in Octave. You can list all .txt files in all subdirectories, filter them by your pattern, then run your code with each. It is much easier to do this in Octave than using Windows Batch scripts. Note that you can call external programs from Octave as well. You really don’t want to double-click manually on thousands of batch files, do you? – Cris Luengo Jun 15 '21 at 01:15
  • Well, kind of, yes :) I only use one design file at a time, so the double click is convenient. If I use Octave without the batch file, I have to start a session, use 'uigetfile' to navigate to the directory, and choose the .txt file. Using the batch file, I just double click and away we go. My script automatically creates a batch file when I do this process (for future uses of that design file), but of course this only helps after the first time I run each individual design file. I'd like to figure out a way to do this without having to do the initial 'uigetfile' routine. Autohotkey maybe? – smcmi Jun 15 '21 at 04:05
  • 1
    I've only gotten more confused about what you are doing. You've got thousands of .txt files. For each you want to run a specific process. But not all today. Today you will run only one specific one, that you choose because it happens to be raining. Tomorrow maybe it's a warm day, so you choose that other one specific file to process. Something like that? And somehow navigating to it in the file explorer is easier than navigating to it in Octave's file selection dialog box? Is that right? – Cris Luengo Jun 15 '21 at 04:46
  • Each .txt file corresponds to a product design, and each has its own folder to keep it separate. When I want to analyze a design, it's more convenient to double-click the batch file (kind of like an executable) than it is to go through Octave directly. It's only for convenience, but there are other users too, so convenience is important. My script creates a batch file when I run directly through Octave, so I can use the .bat on the 2nd, 3rd, 4th, etc times I open the design, but is there a (shortcut) way to create a batch file before using Octave so that this can be done on the 1st run too? – smcmi Jun 15 '21 at 13:09
  • @CrisLuengo, Oh, also yes, it's better to navigate in Explorer than Octave because there are other non-Octave documents/tasks in the directory that require attention, so I ALWAYS have to navigate there in Explorer, and having to do it in Octave too just means I have to do it twice rather than once. My code is replacing an old .exe program, and if the executability functionality is downgraded, my code is going to be a tougher sell to my colleagues than I'd like it to be. Thanks for your advice. – smcmi Jun 15 '21 at 13:19

1 Answers1

1

You might want to compose the answer to your question from calling the script on the right click and running the .m script with command line arguments.

If that fails, uigetfile is certainly not the only method to get file. At the very least you could always copypaste a path string to a folder from explorer to octave function call.

Finally, I guess I'll mention the existence of octave-cli which runs in terminal instead of gui. It might be better suited for running non interactive scripts.

Dimitry
  • 2,204
  • 1
  • 16
  • 24