0

I have created a right-click menu item based on this answer to run a batch file. This batch file runs a command which does some processing on the file. However, if I select multiple files, I see a separate command window for each file opened simultaneously. This is problematic as the command has to completely read and overwrite the file, and the file is on a USB flash drive. I need for each command to complete on a single file before starting on the next file. I also need to be able to select multiple files at once and then have it run, so as to not waste time manually waiting for each file to be processed before starting the next.

How can I get the right-click command to not try to open all files with simultaneous parallel scripts and instead do it in a serial fashion?

Update: As a workaround, I am creating a lock file to act as a semaphore and while this does work, it also opens hundreds or thousands (or however many files are selected) of CMD windows to each run the batch script, which in itself prevents anything else from being done until they are all on the screen, and presumably takes quite a bit of unnecessary resources when only a single command window with a single batch file is really needed at a time. In fact, this makes some functionality unusable while running, such as the ability to alt+tab between apps.

Michael
  • 2,614
  • 6
  • 31
  • 51
  • Use `start /w `, per https://stackoverflow.com/questions/8177695/how-to-wait-for-a-process-to-terminate-to-execute-another-process-in-batch-file/8197920 – DrMoishe Pippik Oct 28 '22 at 01:58
  • @DrMoishePippik Thanks. If I am reading that correct, you put it *in* the batch file? The problem I am having is that Windows Explorer is opening a separate CMD window simultaneously for each file and running a separate invocation of the batch file in each. By the time my batch file is called it's too late. – Michael Oct 28 '22 at 02:14
  • Yes, you'd need to make the batch file iterate through all the arguments (multiple path/files) handed to it through Windows. – DrMoishe Pippik Oct 28 '22 at 02:19
  • @DrMoishePippik That may require a different regedit configuration, as it's currently only passing a single argument, one file to each invocation. – Michael Oct 28 '22 at 02:21
  • See https://learn.microsoft.com/en-us/windows/win32/shell/context?redirectedfrom=MSDN for multiple arguments, e.g. (Default) = C:\MyDir\MyProgram.exe /p "%1" "%2" %3 %4 . That said, I don't know if muliple files are passed as multiple args, nor how to deal with an indefinite number, as does the C printf . – DrMoishe Pippik Oct 28 '22 at 19:27

0 Answers0