0

I want to loop through a folder and its subfolders, get all .jpg files and run myapp.exe on the files where I rename the currently found file's extension. myapp.exe takes the full file path as input and a renamed file as output, like so:

myapp.exe C:\images\original\210_551_210-768--RJF3823klzw.jpg -o C:\images\original\210_551_210-768--RJF3823klzw.gif

I now have this to recursively print the full path of *.jpg files.

for /f "delims=" %%i in ('dir /a-d/b/s *.jpg') do echo "%%i" "%%~ni.gif"

However, this prints only the filename for the second parameter, whereas I want to include the path of the found file.

How can I include the path of the output file, the second parameter for myapp.exe?

Pseudocode:

for /f "delims=" %%i in ('dir /a-d/b/s *.jpg') do myapp.exe "%%i" "<FULLPATH><FILNAME>.gif"
Compo
  • 30,301
  • 4
  • 20
  • 32
Flo
  • 6,070
  • 26
  • 97
  • 171
  • 3
    Are you looking for `"%%~dpni.gif"`? And why use the `myapp.exe`, can you not just use the `Rename` command? `Do Ren "%%i" "%~ni.gif"`. – Compo Apr 28 '18 at 11:20
  • Possible duplicate of [What does %~dp0 mean, and how does it work?](https://stackoverflow.com/questions/5034076/what-does-dp0-mean-and-how-does-it-work) – aschipfl Apr 28 '18 at 11:59

1 Answers1

1

If myapp.exe actually converts the file instead of simply changing the extension then you can use metavariable expansion, (see For /? for examples):

For /F "Delims=" %%A In ('Dir /B/S/A-D *.jpg') Do myapp.exe "%%A" "%%~dpnA.gif"

If you're only replacing the extension the you can just use the rename command:

For /F "Delims=" %%A In ('Dir /B/S/A-D *.jpg') Do Ren "%%A" "%%~nA.gif"

In either case you could also change your for loop to:

For /R %%A In (*.jpg)
Compo
  • 30,301
  • 4
  • 20
  • 32