Both cd
and pushd
will both work with any commands you're trying to use within the batch file - the issue here is that when you try to use subl
it will execute outside of the batch file (ignoring attempts to change the directory). The first thing you're going to want to make sure of is that you have the correct environment variables in place to run Sublime from command.
To do this:
- Go to Control Panel
- Click System
- Click Advanced system settings
- Click Environment Variables...
- Create a New System variable
- Name the variable SUBLIME
- Make the variable value the folder path of your Sublime installation
(i.e. C:\Program Files\Sublime Text 3)
- Click OK
- Edit the Path variable located in your User variables
- Add %SUBLIME% to your variable value (after the
;
)
- Click OK on all the windows to close them
Even when subl
will work from command, the issue remains that the sublime_text.exe
or the subl.exe
will still run from its home directory - regardless of what current directory is set within your batch. To work around this, you'll need to include your target directory in your subl
commands so subl
knows where to go to execute them. You can set your target directory as a variable and use it within the subl
commands:
@echo off
set "dir=C:\folder1\folder2"
subl "%dir%\targetfileorfolder"
Hopefully that helps; it's nothing you're doing wrong in your batch file - it ultimately boils down to the subl
configuration. I was able to find a semi-relevant answer here for Python, and you may be able to do something similar for cmd/batch if you are comfortable changing those kinds of settings (if they are available at all).
setlocal
?