Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/16.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
String 使用PowerShell搜索包含两个或多个特定字符串的文件名_String_Windows_Powershell_Search_Filenames - Fatal编程技术网

String 使用PowerShell搜索包含两个或多个特定字符串的文件名

String 使用PowerShell搜索包含两个或多个特定字符串的文件名,string,windows,powershell,search,filenames,String,Windows,Powershell,Search,Filenames,我想打印目录中的所有文件,这些文件的名称中多次包含特定字符串(而不是文件本身)。有没有办法用Powershell做到这一点 编辑: 这就是我到目前为止所做的: Get ChildItem-Path“Path”-Recurse-Filter*string* 这样,我至少可以得到一次包含该字符串的所有文件,但我只需要出现两次或更多的文件 我只有这个:getchilditem-Path“Path”-Recurse-Filter*string* 太好了 现在,您只需重复以下单词: Get-ChildIt

我想打印目录中的所有文件,这些文件的名称中多次包含特定字符串(而不是文件本身)。有没有办法用Powershell做到这一点

编辑:

这就是我到目前为止所做的:

Get ChildItem-Path“Path”-Recurse-Filter*string*

这样,我至少可以得到一次包含该字符串的所有文件,但我只需要出现两次或更多的文件

我只有这个:
getchilditem-Path“Path”-Recurse-Filter*string*

太好了

现在,您只需重复以下单词:

Get-ChildItem -Path "path" -Recurse -Filter *string*string*

如果所讨论的子字符串有空格,则需要引用字符串:

Get-ChildItem -Path "path" -Recurse -Filter '*looking for this*looking for this*'

如果字符串包含通配符文本(如
[
]
),则可以按如下方式对其进行转义:

$escapedString = [wildcardpattern]::Escape("string [ with special ] characters")
所以整个事情变成了:

$substring = "string we're [looking] for"
$searchTerm = [wildcardpattern]::Escape($substring)
Get-ChildItem -Path "path" -Recurse -Filter "*$searchTerm*$searchTerm*"

是的,那当然有可能。到目前为止,您尝试了什么?很简单,我们可以看到您在代码中遇到的困难吗?我只有以下内容:
Get ChildItem-Path“Path”-Recurse-Filter*string*
这会给我至少一次包含该字符串的所有文件,但我只需要出现两次或两次以上的信息。请将此信息(包括代码片段)添加到您的问题中。提前谢谢。好的,这比我想象的要简单得多。^^谢谢@DonCan94当你知道的时候,你知道;-)不客气!