Opening A Batch File In Notepad++ In The Folder Where Notepad++ Is Opened
Garvit Joshi last edited by
I Made A Batch File Which Would Open In Notepad++ From The CURRENT DIRECTORY where the batch file is located(with run… feature in notepad++), But I Want batch file to open on the folder where i have opened the file.
My Batch File Is Located In
I Have Opened A File Of .java Extension in
I Want to open at file location,i.e.
My batch file Looks like this:
@ECHO OFF ECHO WELCOME TO EXECUTOR ECHO -Garvit Joshi(firstname.lastname@example.org) ECHO USER:%USERNAME% cd /d "%~dp0" :first ECHO LOOKING FOR FILES IN:"%~dp0" set /p "input=Enter The File You Want To Execute:" ECHO =============================== javac %input%.java ECHO =============================== set /p "input=Enter The Class You Want To Run:" ECHO =============================== ECHO OUTPUT: ECHO =============================== java %input% ECHO =============================== pause ECHO ======================================================= ECHO ******************************************************* ECHO ======================================================= goto first
Garvit Joshi last edited by
I Have Asked this question on stackoverflow: https://stackoverflow.com/questions/60395741/opening-a-batch-file-in-notepad-in-the-folder-where-notepad-is-opened?noredirect=1#comment106841929_60395741
PeterJones last edited by
As the folks in SO told you, your batch file is doing a CD into the batch file’s directory; what else did you expect to happen? If you don’t want to change intot hte batch file directory, then you cannot have
cd /d "%~dp0in your batch file.
If you want to run a batch file from within the current file’s directory, or want to have the batch change directory, there are multiple options. For now, I will be using Run > Run as my example, but if you need it as part of your UserDefinedCommands like before, it can be easily tweaked.
I am doing extra, to help you debug things when it goes wrong for you.
changedir then launch batch (so no cd in .bat):
cmd /c "cd /d $(CURRENT_DIRECTORY) & echo %CD% & "D:\Projects\Java\Executor Java.bat" & pause"
cd /d $(CURRENT_DIRECTORY)will change to the directory and drive of the currently active file. If the currently active file is your batch file, that’s what directory it will go to; if your current active file is one of your java files, then that’s the directory it will go to
echo %CD%will print the current directory (after changing) to the cmd window
"D:\Projects\Java\Executor Java.bat"will run the batch file in the active directory – ie, where you just cd’d into
pausewill prompt for hitting enter before exiting the Run>Run command
Or, you could pass the current file’s directory, and do the cd inside the batch file:
@ECHO OFF echo ==== INFO BATCH ==== echo old dir "%cd%" echo arg1 "%~1" echo cd /d "%~dp1" cd /d "%~dp1" echo current dir "%cd%"
Then from the Run>Run, you do a debug command like
cmd /c "cd %TEMP% & "D:\Projects\Java\Executor Java.bat" "$(FULL_CURRENT_PATH)" & pause"
- first I change into TEMP directory, so you know that the cd works properly inside the batch
- then you run the batch, passing it the active file’s full current path (drive, folder, and filename)
- inside the batch, it changes into the drive and folder for the first argument
- then you pause again
When you are done debugging this one, it becomes Run>Run
"D:\Projects\Java\Executor Java.bat" "$(FULL_CURRENT_PATH)"or Run>Run
cmd /c""D:\Projects\Java\Executor Java.bat" "$(FULL_CURRENT_PATH)"", depending on whether you want a wrapper cmd.exe or not
Ekopalypse last edited by
Do you know NppExec plugin?
Maybe worth to have a look.