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

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

Batch file 搜索文件夹目录

Batch file 搜索文件夹目录,batch-file,search,directory,Batch File,Search,Directory,我正在尝试创建一个批处理文件,可以使用该文件键入文件夹名称并搜索多个目录,然后在新窗口中显示结果。示例:我想在3个单独的目录中搜索“tcash”,即\vm-xa01\用户、vm-xa02\用户和vm-xa03\用户。我如何才能做到这一点?原来的问题带有Powershell标签,所以答案是Powershell。对于cmd(批处理)脚本,我强烈建议您无论如何都要进入Powershell。现在是2018年,cmd脚本需要大量调整 在Powershell中,有一个内置的cmdletOut-GridVie

我正在尝试创建一个批处理文件,可以使用该文件键入文件夹名称并搜索多个目录,然后在新窗口中显示结果。示例:我想在3个单独的目录中搜索“tcash”,即\vm-xa01\用户、vm-xa02\用户和vm-xa03\用户。我如何才能做到这一点?

原来的问题带有Powershell标签,所以答案是Powershell。对于cmd(批处理)脚本,我强烈建议您无论如何都要进入Powershell。现在是2018年,cmd脚本需要大量调整

在Powershell中,有一个内置的cmdlet
Out-GridView
,这可能是合适的。例如,要在c:\some\path及其子目录中显示所有txt文件,只需要几个命令。这样,

gci c:\some\path -Recurse | ? { $_.extension -eq ".txt" } | ogv
首先,获取所有文件的递归列表

gci c:\some\path -Recurse
然后选择那些扩展名为.txt的

| ? { $_.extension -eq ".txt" } 
最后,将结果传递给OutGridView(也称为ogv)

| ogv

我还认为PowerShell是执行任务的更好的脚本语言

您可以使用类似于正则表达式的范围来执行dir/Get ChildItem,因此:

Get-ChildItem "\vm-xa0[1-3]\users\tcash" -File -Recurse | Out-Gridview

应该枚举所有匹配的文件并显示在gui窗口中。

Hello!试着发布一些代码来展示你到目前为止所做的尝试,然后社区成员会发现帮助你更容易。老实说,我是一个非常初级的代码。我一路都不确定。是文件名、部分文件名还是目录名?我要找的正是tcash。