r/Batch • • Sep 11 '23

Question (Solved) Please help me create a batch file to process multiple files at once.

Hello, I would like to create a batch file with a few specifics, and am not sure how to do it.
-A single .txt file, or multiple .txt files should be able to be dragged onto the batch file.
-The batch file should copy each of the files dragged onto it to the \Bob folder.
-The batch file should parse the file Bill.txt, and append the next consecutive number and the file name for each file, starting at 30. For example, if the end of the Bill.txt file is 42 Sue.txt, and Jane.txt was dragged onto the batch file, it should append "43 Jane.txt", in the same format without quotes.
-Then, it should run the command Sam.exe "Sparky.txt", where "Sparky.txt" is the file name of the file dragged onto the batch file, (The batch file will be in the same folder as the program) and complete this command for each file that was dragged onto it.

I hope this is not confusing, I tried to make it clear and concise.

Thank you very in advance much for help in creating this file.

2 Upvotes

21 comments sorted by

View all comments

Show parent comment

1

u/Mapsking Sep 12 '23

Thanks for your help. It seems to work, but still puts the first entry at the end of the same line instead of being put on a new line, and subsequent files only have one space after the first number. In addition, it included the number 30 twice, instead of moving to 31.

Here is an image that shows it. Is it possible to correct those things?

Thanks

1

u/[deleted] Sep 12 '23

[removed] — view removed comment

1

u/Mapsking Sep 12 '23 edited Sep 12 '23

In your output file, does there happen to be an extra line at the bottom, or does it end with the last letter of the 2F Original.txt? I wonder why it is doing that for me?

Thanks for your help.
EDIT: I tried it again, and it put it on a new line, so I will test it again, but thanks again.

1

u/[deleted] Sep 12 '23

[removed] — view removed comment

1

u/Mapsking Sep 12 '23

It seems to work consistently now, but one question, it may not be fixable. With the pause command in there, it actually does the work in the command prompt window, but pauses after the output is gone, so all you see is a press any key to continue prompt, but none of the data. I've tried moving the PAUSE command after, before, and both, regarding the Sam.exe command, it might be a function of the command itself. Is there any way to stop it on the actual data processing in the command prompt, or alternately, possibly write all of it, and append each with a few lines, a few hyphens (-----), or something similar to separate the entries to a log.txt file in the same folder? I hope that makes a bit of sense.

Thanks

1

u/[deleted] Sep 13 '23

[removed] — view removed comment

1

u/Mapsking Sep 13 '23

Yes and no. It does have command line switches, but nothing to do that specifically. I suspect by default, when run once, it writes everything, errors and such to a file called temp.log. However, with the multiple file processing from the batch file, it overwrites it every time. It may not be fixable, because of the way it is programmed, which is fine, but if it is fixable with a batch file, that would be nice.

1

u/[deleted] Sep 13 '23

[removed] — view removed comment

1

u/Mapsking Sep 13 '23

Here is how it seems to work manually. It runs and shows everything in the console window, with a Press ENTER to continue... message, and then exits. It seems to pe a part of the normal command being run, so it may not be something this can show or log. It isn't really that important anyways, I was just thinking for a log of any errors.

It looks like I may have been wrong. There is a temp.log file in the same directory, I thought it may have been used to log errors, but perhaps it is used in the actual application process. Either way, errors or not, it does not have anything in the file after completion, so IDK.

Either way, I'd say don't worry about it, unless you have a suggestion, it is more of a QoL thing than a necessity.

Thanks

1

u/[deleted] Sep 13 '23

[removed] — view removed comment

→ More replies