There can be used the following lines in the batch file 3DS.cmd
if this batch file is stored in root of the SD card and is executed from the SD card mounted as drive with a drive letter:
@echo off
echo Keeping window active for GOG time tracking
cd /D "%~d0\Games\RetroArch"
retroarch.exe -L cores\citra_libretro.dll %1 -f
The usage help of command CALL output on running call /?
in a command prompt window explains how to reference the arguments of a batch file. There is always the argument 0 even on batch file is executed without any argument string passed to the batch file by a user or another process.
%0
references the string used to start the execution of the batch file. On double clicking on a batch file stored on an SD card mounted with a drive letter by Windows, %0
expands to the fully qualified file name of the batch file on the SD card enclosed in "
because of the Windows File Explorer starts in background:
C:\WINDOWS\system32\cmd.exe /c ""Animal Crossing New Leaf.cmd" "
The usage help of the Windows Command Processor cmd.exe
output on running cmd /?
explains how the arguments are interpreted by cmd.exe
in this case. The first and the last "
are removed from the command line. The started cmd.exe
executes therefore:
"E:\Animal Crossing New Leaf.cmd"
That string with the double quotes is argument 0 of the executed batch file.
%~d0
can be used in the batch file to reference just the drive letter and the colon of the currently running batch file respectively \\
if the batch file is stored on a network resource executed using its UNC path.
The code above works only for batch file being stored in root of a storage media mounted with a drive letter.
A code for 3DS.cmd
working always independent on which storage media the batch file is stored and in which directory and how the batch file is started as long as the directory Games
is a subdirectory of the directory containing the batch file is:
@echo off
setlocal EnableExtensions DisableDelayedExpansion
cls
if "%~1" == "" echo ERROR: %~nx0 called without game file name!& pause & exit /B
pushd "%~dp0Games\RetroArch"
echo Keeping window active for GOG time tracking
retroarch.exe -L cores\citra_libretro.dll %1 -f
popd
endlocal
%~dp0
expands to full path of the batch file always ending with a backslash.
See also: What is the reason for batch file path referenced with %~dp0 sometimes changes on changing directory? The bug of cmd.exe
does not matter here because of %~dp0
is used before changing the current directory the first time with the command PUSHD.
The batch file Animal Crossing New Leaf.cmd
stored in same directory as 3DS.cmd
should contain only the single command line:
@call "%~dp03DS.cmd" "%~dp0Games\Nintendo\3DS\Games\Animal Crossing New Leaf.3ds"
The two batch files can be used with these improvements also on copying all directories and files on the SD card to a directory of user´s choice like %UserProfile%\RetroGames
.
It is also possible to use only one batch file with name Animal Crossing New Leaf.cmd
stored in the directory with the subdirectory Games
and all the other directories and files with the following lines:
@echo off
setlocal EnableExtensions DisableDelayedExpansion
pushd "%~dp0Games\RetroArch" || (echo ERROR: Missing subdirectory "Games\RetroArch"& pause & exit /B)
echo Keeping window active for GOG time tracking
retroarch.exe -L cores\citra_libretro.dll "%~dp0Games\Nintendo\3DS\Games\Animal Crossing New Leaf.3ds" -f
popd
endlocal
To understand the commands used and how they work, open a command prompt window, execute there the following commands, and read the displayed help pages for each command, entirely and carefully.
call /?
cd /?
echo /?
endlocal /?
exit /?
if /?
pause /?
popd /?
pushd /?
setlocal /?