Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have the following batch command to open files with 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 do I change this batch command to open all files with dtd extension under "D:\data" folder ?

I tried the below code but it does not work

REM Open all the static content files
"C:\Program Files (x86)\Notepad++\notepad++.exe" "D:\data\\*.dtd"
like image 264
NewUnhandledException Avatar asked Dec 17 '14 12:12

NewUnhandledException


People also ask

How do I open a batch file in Notepad?

To open the BAT file in Notepad, right-click it and choose Show more options > Edit from the menu (or just Edit in some Windows versions). You might find it helpful to use more advanced text editors that support syntax highlighting when editing a BAT file.

What is %% f in batch file?

%%parameter A replaceable parameter: in a batch file use %%G (on the command line %G) FOR /F processing of a text file consists of reading the file, one line of text at a time and then breaking the line up into individual items of data called 'tokens'.

What is %% K in batch file?

So %%k refers to the value of the 3rd token, which is what is returned.

What does %% A mean in batch file?

%%a refers to the name of the variable your for loop will write to. Quoted from for /? : FOR %variable IN (set) DO command [command-parameters] %variable Specifies a single letter replaceable parameter. (set) Specifies a set of one or more files.


2 Answers

You can use the FOR command:

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

Walks the directory tree rooted at [drive:]path, executing the FOR statement in each directory of the tree. If no directory specification is specified after /R then the current directory is assumed. If set is just a single period (.) character then it will just enumerate 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 this from a batch file

If you want to use multiple extensions you can separate those with a space

FOR /R d:\data %a IN (*.dtd *.xml *.xslt) DO "C:\Program Files (x86)\Notepad++\notepad++.exe" "%a"
like image 55
rene Avatar answered Nov 09 '22 11:11

rene


You might also want to write the batch file in this way:

set command=C:\Program Files (x86)\Notepad++\notepad++.exe
FOR /R d:\data %%a IN (*.dtd) DO %command% %%a
like image 27
Ali Nem Avatar answered Nov 09 '22 12:11

Ali Nem