Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file 批处理命令,用于在记事本++;_Batch File_Filesystems - Fatal编程技术网

Batch file 批处理命令,用于在记事本++;

Batch file 批处理命令,用于在记事本++;,batch-file,filesystems,Batch File,Filesystems,我使用以下批处理命令打开扩展名为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++\n

我使用以下批处理命令打开扩展名为
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"
如何更改此批处理命令以打开
“D:\data”
文件夹下扩展名为
dtd
的所有文件

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

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

您可以使用
FOR
命令:

FOR/R[[drive:]path]%(设置)DO命令[命令参数]中的变量

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

在您的情况下,这应该有效:

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"

您可能还希望以以下方式写入批处理文件:

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

如果不希望打开上一个会话中的文件,请添加
-nosession
参数。
(此处为
.bat
文件中的
dtd
扩展名示例)


有可能在in(set)部分同时包含几个fileending吗?@Kaiserludi是的,事实证明是可能的,我在回答中添加了这个选项。
for /R %%x in (*.dtd) do (
    start "" "C:\Program Files\Notepad++\notepad++.exe" -nosession "%%x"
)