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

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了批处理命令在Notepad ++中打开某种类型的所有文件相关的知识,希望对你有一定的参考价值。

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

REM Open all the static content files
"C:Program Files (x86)Notepad++
otepad++.exe" "D:datafolder1File1.dtd"
"C:Program Files (x86)Notepad++
otepad++.exe" "D:datafolder1File2.dtd"
"C:Program Files (x86)Notepad++
otepad++.exe" "D:datafolder2File1.dtd"
"C:Program Files (x86)Notepad++
otepad++.exe" "D:datafolder2File2.dtd"
"C:Program Files (x86)Notepad++
otepad++.exe" "D:datafolder3File1.dtd"
"C:Program Files (x86)Notepad++
otepad++.exe" "D:datafolder3File2.dtd"

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

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

REM Open all the static content files
"C:Program Files (x86)Notepad++
otepad++.exe" "D:data\*.dtd"
答案

您可以使用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++
otepad++.exe" "%a"

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

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

FOR /R d:data %a IN (*.dtd *.xml *.xslt) DO "C:Program Files (x86)Notepad++
otepad++.exe" "%a"
另一答案

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

set command=C:Program Files (x86)Notepad++
otepad++.exe
FOR /R d:data %%a IN (*.dtd) DO %command% %%a
另一答案

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

for /R %%x in (*.dtd) do (
    start "" "C:Program FilesNotepad++
otepad++.exe" -nosession "%%x"
)

以上是关于批处理命令在Notepad ++中打开某种类型的所有文件的主要内容,如果未能解决你的问题,请参考以下文章

命令行下打开记事本,并添加内容。

怎样用cmd执行vbs脚本,求简单实用命令

Windows系统 notepad命令详解,Windows系统打开记事本

用易语言写的DLL怎么样再用易语言打开

如何用命令打开记事本

Windows在cmd命令行下打开常用工具的命令