【问题标题】:Why does findstr also search in files outside specified directory?为什么 findstr 还要在指定目录之外的文件中搜索?
【发布时间】:2016-01-13 04:36:44
【问题描述】:

findstr 有一个我在 Windows 7 上不理解的简单行为。

我在多个不同位置使用以下脚本以管理员模式运行批处理文件(如果不是,它们根本不会启动):

@echo off
set local=%~dp0
echo %local%
REM to check that I am where I think I am
findstr /s /i /c:"stringtofind" %local%*.ext

当我从"C:\Program files\~""C:\Program files (x86)\~" 中的位置运行此脚本时,输出包括%local% 目录和带有"stringtofind" 的子目录之外的.ext 文件。实际上所有匹配的文件都在硬盘上。

这种行为不会出现在我可以测试的所有其他位置(基本上在 C:\ 目录中的任何其他位置),其中仅出现目录和子目录中的匹配文件。

Program files 目录有什么特定的吗?

【问题讨论】:

    标签: windows batch-file windows-7 findstr


    【解决方案1】:

    尝试更改为

    findstr /s /i /c:"stringtofind" "%local%*.ext"
    

    在您提到的情况下,目录名称包含空格,因此findstr 正在查找多个参数。 “使用引号”将“包含空格的字符串”组合成一个字符串。

    【讨论】:

    • 确实是这样,感谢您的解决方案!
    猜你喜欢
    • 2014-05-15
    • 1970-01-01
    • 1970-01-01
    • 2011-08-12
    • 1970-01-01
    • 1970-01-01
    • 2014-01-29
    • 2012-08-27
    • 1970-01-01
    相关资源
    最近更新 更多