2016-08-05 40 views
1

我是windows脚本中的新手,所以请耐心等待。通过Windows命令行搜索和组织数据

我想从多个文件夹中找到“测试”文件夹。从多条路径,如

搜索测试文件夹:

/rbl.com/mailroot/test 
/pml.com/mailroot/test 
/pax.com/mailroot/ 

想要得到的输出这样的:

[email protected] 
[email protected] 

我已经运行此命令,得到的结果dir /S test > c:\results.txt

输出:

Volume in drive C has no label. 
Volume Serial Number is 4A9E-06D4 

Directory of C:\Program Files (x86)\Parallels\Plesk\Mail Servers\Mail Enable\Postoffices\rbl.com\MAILROOT 

08/05/2016 12:36 AM <DIR>   test 
     0 File(s)    0 bytes 

Directory of C:\Program Files (x86)\Parallels\Plesk\Mail Servers\Mail Enable\Postoffices\pml.com\MAILROOT 

08/05/2016 12:36 AM <DIR>   test 
     0 File(s)    0 bytes 

但如何提取的信息等:

[email protected] 
[email protected] 
+0

您正在使用哪个版本的PowerShell(请参阅'$ PSVersionTable.PSVersion.Major')? –

回答

0

这应该做的伎俩

ls test -Directory -Recurse | % { "$($_.Name)@$($_.Parent.Parent.Name)" } 

它递归搜索您的文件夹的测试文件夹,然后打印出来的文件夹的父它的父,和该文件夹的名称,如你想要的格式。

+0

反过来。 ''{0} @ {1}“-f $ _。Name,$ _. Parent.Parent.Name' –

+0

我有运行命令'ls test -Directory -Recurse | %{“$($ _。Parent.Parent.Name)@ $($ _。Name)”}'显示如下输出: **[email protected]** ** aoryxcarrental.ae @测试** – blaCkninJa

+0

它的工作原理我已经通过这种方式运行相同的命令'ls test -Directory -Recurse | %{“$($ _。Name)@ $($ _。Parent.Parent.Name)”}' – blaCkninJa