2015-10-13 51 views
-1

我有一个包含关键字列表的平面文件。我可以格式化这个文件,但它是需要的。从列表中搜索关键字(在文件中)并返回完整路径

我想搜索服务器上的关键字,我希望脚本将包含该关键字的所有路径返回到文件。完整路径+文件名会更好。

我需要在满载服务器上查找图像,每次搜索需要30-60秒。我们需要找到约1000个关键字。因此,如果我能得到一个能搜索所有内容并将其报告给excel文件的脚本,那么这将节省时间。

Product1 c:\products\collection1\season2\product1.psd 
Product1 c:\products\collection2\season3\product1-back.psd 
Product1 c:\products\collection1\rejected\front-product1.txt 
Product2 c:\products\collection3\season1\product2-back.pdf 
Product3 c:\products\collection2\season4\product3-new.tif 

P.S.:我的平面文件所需的输出文件的

Product1 
Product2 
Product3 

实施例的

实施例返回的路径将是UNC路径,如\\server\products\collection

+0

为什么你这是完全不同的两种东西'powershell'和'批量file'标签(尽管你可以嵌入双方)? – wOxxOm

+0

我添加了PowerShell和批处理文件,因为我不关心最终结果的方法。 – user5442433

回答

0

然后,它完全写出来,让对象跟踪的结果:

$searchWords = gc c:\filename.txt 
$results = @() 
Foreach ($sw in $searchWords) 
{ 
    $files = gci -path C:\products -filter "*$sw*" -recurse | select FullName 

    foreach ($file in $files) 
    { 
     $object = New-Object System.Object 
     $object | Add-Member -Type NoteProperty –Name SearchWord –Value $sw 
     $object | Add-Member -Type NoteProperty –Name FoundFile –Value $file 
     $results += $object 
    } 

} 

$results | Export-Csv result.csv -Delimiter "`t" -NoTypeInformation 
+0

非常好!你节省了我的一天 – user5442433

0

这是什么意思?

gc filename.txt | % {gci -path c:\products -filter "*$_*" -recurse} | select FullName | Export-Csv result.csv -Delimiter "`t" 
+0

它的超棒!完全符合我的意图。唯一能让它更有效的是,如果我可以在路径之前输出文件中的关键字名称,例如: product1,路径 – user5442433

相关问题