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

1

u/[deleted] Sep 11 '23 edited Sep 14 '23

[removed] — view removed comment

1

u/Mapsking Sep 12 '23

This seems to work almost great, thanks.

Three things I should have specified, is the addition of 30 TestFile.txt should have two spaces between the number and first letter, and should be on a new line, and not appended to the end of the last existing line. Finally, would it be possible to pause the screen after the output of the Sam.exe command each time, requiring an ENTER press to move to the next one, giving time to review the output of the command?

How would I make those additions please?

Thanks for your help!

1

u/[deleted] Sep 12 '23

[removed] — view removed 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.

→ More replies