Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.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 - Fatal编程技术网

Batch file 限制批处理文件

Batch file 限制批处理文件,batch-file,Batch File,我有一些简短的.bat文件,用于生成文件规范列表。例如: C: cd\Users\garys\Documents dir *.xlsm /s /b > %userprofile%\Desktop\xlsm.txt 将生成如下内容: C:\Users\garys\Documents\My Spreadsheets\autocorrect.xlsm C:\Users\garys\Documents\My Spreadsheets\column id.xlsm C:\Users\garys\

我有一些简短的
.bat
文件,用于生成文件规范列表。例如:

C:
cd\Users\garys\Documents
dir *.xlsm /s /b  > %userprofile%\Desktop\xlsm.txt
将生成如下内容:

C:\Users\garys\Documents\My Spreadsheets\autocorrect.xlsm
C:\Users\garys\Documents\My Spreadsheets\column id.xlsm
C:\Users\garys\Documents\My Spreadsheets\control word.xlsm
C:\Users\garys\Documents\My Spreadsheets\Data.xlsm
C:\Users\garys\Documents\My Spreadsheets\Dinar.xlsm
但如果我使用:

C:
cd\Users\garys\Documents
dir *.xls /s /b  > %userprofile%\Desktop\xls.txt
我生成的文本文件包括扩展名为.xls的文件以及扩展名为.xlsmxlsx的文件

如何修改
.bat
脚本以忽略.xlsm.xlsx文件

dir *.xls /s /b |findstr /i /e /C:".xls" > %userprofile%\Desktop\xls.txt
应该提供你的数据

dir
命令输出到
findstr
,该命令将以不区分大小写的方式查找
/e
结束
/c的所有行:“此字符串”
/i

应该提供你的数据


dir
命令输出到
findstr
,该命令将查找
/e
结束的所有行
/c:“this string”
/i以不区分大小写的方式这种行为的原因是
dir*.xls
还检查短文件名,例如,对于
autocorrect.xlsm
,它类似于
autoco~1.xls

如中所示,通过
findstr
进行附加筛选的另一种方法是使用,我相信这是Windows自Vista以来的固有功能,并对文件名和通配符进行不同的处理:

cd/D“C:\Users\garys\Documents”
其中“.*.xls”>%userprofile%\Desktop\xls.txt”
前缀
确保只返回当前目录中的匹配文件;否则,
where
也会在系统路径目录中搜索(键入以显示它)


where
命令的缺点是,它还使用
PATHEXT
变量中定义的扩展名(键入
set PATHEXT
以显示它们),因此如果列表中有文件
something.xls.exe
PATHEXT
包含
.exe
,则该文件也会返回。一种可能的解决方法是临时删除变量
PATHEXT
,但必须确保随后立即恢复它。

这种行为的原因是
dir*.xls
也会检查短文件名,我想这类似于
autocorrect.xlsm的
autoco~1.xls
,比如说

如中所示,通过
findstr
进行附加筛选的另一种方法是使用,我相信这是Windows自Vista以来的固有功能,并对文件名和通配符进行不同的处理:

cd/D“C:\Users\garys\Documents”
其中“.*.xls”>%userprofile%\Desktop\xls.txt”
前缀
确保只返回当前目录中的匹配文件;否则,
where
也会在系统路径目录中搜索(键入以显示它)


where
命令的缺点是,它还使用
PATHEXT
变量中定义的扩展名(键入
set PATHEXT
以显示它们),因此如果列表中有文件
something.xls.exe
PATHEXT
包含
.exe
,则该文件也会返回。一种可能的解决方法是临时删除变量
PATHEXT
,但是您必须确保随后立即将其恢复。

DIR
导入
FINDSTR
命令,并告诉它使用
/E
选项在字符串末尾查找XLS。将
DIR
导入
FINDSTR
命令,并告诉它使用
/E
选项在字符串末尾查找XLS。