Chr901
Chr901

Reputation: 45

Open multiple .bat files with NotePad++ using a .bat file

Currently I use .bat files such as the following to open multiple .yml files across different location:

START "C:\Program Files\Notepad++\notepad++.exe" "D:\Location 1\settings.yml"
START "C:\Program Files\Notepad++\notepad++.exe" "D:\Location 2\settings.yml"
START "C:\Program Files\Notepad++\notepad++.exe" "D:\Location 3\settings.yml"
START "C:\Program Files\Notepad++\notepad++.exe" "D:\Location 4\settings.yml"

This works correctly for .txt, .yml, .json, files and more. However if I attempt to use the same procedure for opening .bat files, it fails.

Example:

START "C:\Program Files\Notepad++\notepad++.exe" "D:\Location 1\start1.bat"
START "C:\Program Files\Notepad++\notepad++.exe" "D:\Location 2\start2.bat"
START "C:\Program Files\Notepad++\notepad++.exe" "D:\Location 3\start3.bat"
START "C:\Program Files\Notepad++\notepad++.exe" "D:\Location 4\start4.bat"

My goal is to open these .bat files in notepad++ for editing. Instead, windows actually attempts to open the start*.bat files themselve outside of notepad++

Upvotes: 0

Views: 858

Answers (1)

Compo
Compo

Reputation: 38579

Your example syntax is incorrect.

Please open a Command Prompt window, type start /?, and press the ENTER key to see its usage information.

START ["title"] [command/program] [parameters]

Your working syntax, is only working by luck, because it is seeing "C:\Program Files\Notepad++\notepad++.exe" as the title, and then opening a registered filetype .yml using its default program. Luckily your default program for those files is Notepad++, and that is the only reason it is working as intended.

The syntax you should be using is:

@Start "" "%ProgramFiles%\Notepad++\notepad++.exe" "D:\Location 1\settings.yml"
@Start "" "%ProgramFiles%\Notepad++\notepad++.exe" "D:\Location 2\settings.yml"
@Start "" "%ProgramFiles%\Notepad++\notepad++.exe" "D:\Location 3\settings.yml"
@Start "" "%ProgramFiles%\Notepad++\notepad++.exe" "D:\Location 4\settings.yml"

…and

@Start "" "%ProgramFiles%\Notepad++\notepad++.exe" "D:\Location 1\start1.bat"
@Start "" "%ProgramFiles%\Notepad++\notepad++.exe" "D:\Location 2\start2.bat"
@Start "" "%ProgramFiles%\Notepad++\notepad++.exe" "D:\Location 3\start3.bat"
@Start "" "%ProgramFiles%\Notepad++\notepad++.exe" "D:\Location 4\start4.bat"

The first set of (empty) double-quotes is the window title, (the title doesn't need to be empty), and is required because the start command treats the first double-quoted argument as a title.

Upvotes: 3

Related Questions