Aidan Kehoe Aidan Kehoe - 1 year ago 218 Question

Run batch file in

I'm trying to run a batch file in This is the command I'm using:


The batch file is supposed to crawl through the folder it is located in and convert all the .tif files to .png. When I call the file, the command window opens (so I know something is happening), however none of the .tif files are converted. When I simply double click on the batch file in the directory, it runs properly (so I know it is not a problem with the batch file). Why is my code not running the batch file correctly?
Here is the code in the batch file:

for /r %%a in (.) do (
pushd %%a
"C:\Program Files (x86)\IrfanView\i_view32.exe" *.tif /convert=*.png /transpcolor=(255,255,255)
erase /f/q *.tif


Answer Source

You can amend your batch file to refer to the absolute path where the files are located.

for /r %%a in (C:\Folder) do ( ... etc, etc.

Or, you can use a ProcessStartInfo object instead so that your VB.Net application knows which folder to start the processs in as its default folder. Your batch file would then be fine. However, I'd argue that it's better to amend the batch file, as it won't work unless it's run in that specific folder, which you should probably avoid. You could pass the directory to process as a parameter to the batch file.

See here for further info on the WorkingDirectory parameter of the ProcessStartInfo object.

And here for an example (C#, but easily amended to VB.Net): c# ProcessStartInfo

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download