批处理命令在Notepad ++中打开某种类型的所有文件

问题描述 投票:5回答:3

我有以下批处理命令来打开带有dtd扩展名的文件。

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"

如何更改此批处理命令以在dtd文件夹下打开"D:\data"扩展名的所有文件?

我尝试了下面的代码,但它不起作用

REM Open all the static content files
"C:\Program Files (x86)\Notepad++\notepad++.exe" "D:\data\\*.dtd"
batch-file filesystems
3个回答
9
投票

您可以使用FOR命令:

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

遍历以[drive:]路径为根的目录树,在树的每个目录中执行FOR语句。如果在/ R之后没有指定目录规范,则假定当前目录。如果set只是一个句点(。)字符,那么它将枚举目录树。

在你的情况下,这应该工作:

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

如果需要从批处理文件中运行,请使用%%a

如果要使用多个扩展,可以使用空格分隔

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

2
投票

您可能还希望以这种方式编写批处理文件:

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

0
投票

如果您不想打开上一个会话中的文件,请添加-nosession参数。 (这里是dtd文件中.bat扩展的示例)

for /R %%x in (*.dtd) do (
    start "" "C:\Program Files\Notepad++\notepad++.exe" -nosession "%%x"
)
© www.soinside.com 2019 - 2024. All rights reserved.