Would be great if could auto get current working directory inside Open With command e.g. when using shortcut %file_dir%
If right click on file D:\images\image1.jpg and select Open with then command as follows do_something.bat %file_dir% that would translate to do_something.bat "D:\images\".
Open With - get current folder path
Moderators: helmut, XnTriq, xnview
-
- Posts: 22
- Joined: Wed Mar 18, 2020 12:21 pm
Re: Open With - get current folder path
Something like this should work:
<name of batch file used in "open with" command>.bat:
______________________________________
rem this batch file calls another batch file within image's working directory
@echo off
rem here is working directory of image
echo\Path to image: %~dp1
rem this calls the do_something.bat with working directory
cmd /c "<path to do_something.bat>\do_something.bat %~dp1"
pause
______________________________________
<name of batch file used in "open with" command>.bat:
______________________________________
rem this batch file calls another batch file within image's working directory
@echo off
rem here is working directory of image
echo\Path to image: %~dp1
rem this calls the do_something.bat with working directory
cmd /c "<path to do_something.bat>\do_something.bat %~dp1"
pause
______________________________________
-
- Posts: 22
- Joined: Wed Mar 18, 2020 12:21 pm
Re: Open With - get current folder path
So no need to change xnviewmp as info is already being passed with "open with" command.
My example works better setting an environment variable with set command in batch file, as spaces in path name could be an issue otherwise.
Tested, worked in win11.
Here is a more polished example.
Associate batch file to "open with" command:
1. create f:\workingdir.bat:
______________________________________
@echo off
rem this batch file opens and passes working directory of image to another batch file:
echo.
echo.
echo batch %~n0
echo.
rem set working directory to environment variable %file_dir%
set file_dir=%~dp1
rem here is working directory of image using modifiers and command line parameter variable %1 that is passed to this patch file with "open with" command
echo\Path to image using modifier: %~dp1
rem here is working directory of image that is saved
echo\Path to image using environment variable: %file_dir%
rem this opens the do_something.bat with %file_dir% working dir variable
cmd /c "f:\do_something.bat %file_dir%"
pause
______________________________________
2. create f:\do_something.bat:
_________________________________
@echo off
rem this batch file has an enironment variable passed to it that holds working directory for image
echo.
echo.
echo batch %~n0
echo.
rem here is working directory of image using modifiers and command line parameter variable %1 that is passed to this patch file with "open with" command
rem this command may not display working directory of image properly if for example there is a space in the path
echo\Path to image using modifier: %~dp1
rem here is working directory of image that is saved
echo\Path to image using environment variable: %file_dir%
_________________________________
3. associate Xnviewmp's "open with -> configure programs" to f:\workingdir.bat
4. right click on image in xnviewmp browser, "open with" f:\workingdir.bat
My example works better setting an environment variable with set command in batch file, as spaces in path name could be an issue otherwise.
Tested, worked in win11.
Here is a more polished example.
Associate batch file to "open with" command:
1. create f:\workingdir.bat:
______________________________________
@echo off
rem this batch file opens and passes working directory of image to another batch file:
echo.
echo.
echo batch %~n0
echo.
rem set working directory to environment variable %file_dir%
set file_dir=%~dp1
rem here is working directory of image using modifiers and command line parameter variable %1 that is passed to this patch file with "open with" command
echo\Path to image using modifier: %~dp1
rem here is working directory of image that is saved
echo\Path to image using environment variable: %file_dir%
rem this opens the do_something.bat with %file_dir% working dir variable
cmd /c "f:\do_something.bat %file_dir%"
pause
______________________________________
2. create f:\do_something.bat:
_________________________________
@echo off
rem this batch file has an enironment variable passed to it that holds working directory for image
echo.
echo.
echo batch %~n0
echo.
rem here is working directory of image using modifiers and command line parameter variable %1 that is passed to this patch file with "open with" command
rem this command may not display working directory of image properly if for example there is a space in the path
echo\Path to image using modifier: %~dp1
rem here is working directory of image that is saved
echo\Path to image using environment variable: %file_dir%
_________________________________
3. associate Xnviewmp's "open with -> configure programs" to f:\workingdir.bat
4. right click on image in xnviewmp browser, "open with" f:\workingdir.bat
-
- Posts: 298
- Joined: Sun Apr 23, 2023 5:14 am
Re: Open With - get current folder path
This approach requires using .bat files, what if i want to use some other scripting language like AutoHotkey perhaps and dont want to create .bat file that will in its turn launch AHK script. Perhaps its best to implement anyway for greater flexibility.smithcferg wrote: Tue May 13, 2025 3:28 pmSo no need to change xnviewmp as info is already being passed with "open with" command.
P.S. also there's limitation to 256 or so characters to how many additional fields can be supplied to bat file so its not ideal to use bat files.