[SOLVED] Run an EXE from a different directory?

Issue

This Content is from SuperUser. Question asked by argo

I feel a little embarrassed to ask but struggling to piece it all together here.

I have a folder containing magazines, whose pages are in JPEG image format. Like so:

folders

folder contents

I have img2pdf.exe located in a separate folder. I wish to loop through all the folders, and execute img2pdf inside them, for instance with the following arguments

img2pdf.exe *.jpeg -o ####.pdf 

But #### is replaced with the current directory’s file name through a Windows CMD variable etc. As you can see, I want the issue of the magazine (folder name) as the pdf file name.

What I have found so far

I can execute img2pdf from a different directory as described here, but all manual inputs etc including file name.

I can loop through folders and execute something as described here, but it fails to produce a .pdf in each folder. Instead, it produces a single 0kb .pdf file at the root directory. And I tried to get the current folder name as the pdf file name, but it didn’t work, the file was simply called %~nxI.pdf:

for /D %G in ([folder directory]) do "[img2pdf.exe location]" *.jpg -o "%~nxI".pdf "%~fG"

So – any pointers?



Solution

You should use a backslash \, instead of forward slash. /

C:\dirZero> dirOne\myProgram.exe

Or, wrap it with double quotes "

C:\dirZero> "dirOne/myProgram.exe"


This Question was asked in StackOverflow by Ben and Answered by Ruel It is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?