Use
cmd /C for /F "delims=" %%G in ("%1") do magick convert "%~G" "%~nG.jpg"
or
cmd /C for /F "delims=" %%G in ("%1") do magick convert "%~G" "%~dpnG.jpg"
The former line tested using the following registry hack
reg query "HKEY_CLASSES_ROOT\pngfile\shell\ForLoop\Command"
HKEY_CLASSES_ROOT\pngfile\shell\ForLoop\Command
(Default) REG_SZ cmd /C for /F "delims=" %%G in ("%1") do CliParserPause.exe convert "%~G" "%~nG.jpg"
and using the following simple C++ program which lists all its command line parameters supplied (and then pauses to enable observing its output):
// CliParserPause.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <wchar.h>
#include <cstdio>
#include <stdlib.h>
int main(int argc, wchar_t* argv[])
{
for (int i = 0; i < argc; ++i)
{
wprintf(L"param %d = %S\n", i, argv[i]);
}
wprintf(L"press any key to continue...");
std::getchar();
exit(-999 - argc); /* exitcode to OS = ( -1000 -supplied_paramaters_count ) */
return 0;
}
Test case output:
C:\WINDOWS\system32> CliParserPause.exe convert "D:\bat\SO\Loading1.png" "Loading1.jpg"
param 0 = CliParserPause.exe
param 1 = convert
param 2 = D:\bat\SO\Loading1.png
param 3 = Loading1.jpg
press any key to continue...
Another test case shows some non-trivial example with spaces in path and file name:
C:\WINDOWS\system32> CliParserPause.exe convert "D:\bat\odds and ends\a b\c d\e f\File Explorer Properties.png" "File Explorer Properties.jpg"
param 0 = CliParserPause.exe
param 1 = convert
param 2 = D:\bat\odds and ends\a b\c d\e f\File Explorer Properties.png
param 3 = File Explorer Properties.jpg
press any key to continue...
Thank you! The latter of the two examples you posted works perfectly. – LittleKingJohn – 2019-08-10T13:31:21.153