Batch command to open all files of a certain type in Notepad ++

I have the following command command to open files with the dtd extension.

 REM Open all the static content files "C:\Program Files (x86)\Notepad++\notepad++.exe" "D:\data\folder1\File1.dtd" "C:\Program Files (x86)\Notepad++\notepad++.exe" "D:\data\folder1\File2.dtd" "C:\Program Files (x86)\Notepad++\notepad++.exe" "D:\data\folder2\File1.dtd" "C:\Program Files (x86)\Notepad++\notepad++.exe" "D:\data\folder2\File2.dtd" "C:\Program Files (x86)\Notepad++\notepad++.exe" "D:\data\folder3\File1.dtd" "C:\Program Files (x86)\Notepad++\notepad++.exe" "D:\data\folder3\File2.dtd" 

How can I change this command to open all files with the dtd extension in the "D:\data" folder?

I tried the code below, but it does not work

 REM Open all the static content files "C:\Program Files (x86)\Notepad++\notepad++.exe" "D:\data\\*.dtd" 
+5
source share
3 answers

You can use the FOR command:

FOR /R [[drive:]path] %variable IN (set) DO command [command-parameters]

Projects a directory tree on the root path [drive:], executing FOR in each directory of the tree. If no directory specification is specified after / R, then the current directory is assumed. If only one period (.) Is set, then it will simply list the directory tree.

In your case, this should work:

 FOR /R d:\data %a IN (*.dtd) DO "C:\Program Files (x86)\Notepad++\notepad++.exe" "%a" 

Use %%a if you need to run it from a batch file

If you want to use multiple extensions, you can highlight them with a space

 FOR /R d:\data %a IN (*.dtd *.xml *.xslt) DO "C:\Program Files (x86)\Notepad++\notepad++.exe" "%a" 
+7
source

You can also write a batch file as follows:

 set command=C:\Program Files (x86)\Notepad++\notepad++.exe FOR /R d:\data %%a IN (*.dtd) DO %command% %%a 
+1
source

If you do not want the files from the previous session to be opened, add the -nosession .
(here is an example of the dtd extension in the .bat file)

 for /R %%x in (*.dtd) do ( start "" "C:\Program Files\Notepad++\notepad++.exe" -nosession "%%x" ) 
0
source

Source: https://habr.com/ru/post/1209343/


All Articles