【问题标题】:Search and Organize Data through windows command line通过 windows 命令行搜索和组织数据
【发布时间】:2016-08-05 10:07:23
【问题描述】:

我是 Windows 脚本的新手,请耐心等待。

我想从多个文件夹中找到“test”文件夹。比如

从多个路径搜索测试文件夹:

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

想要得到这样的输出:

test@rbl.com
test@pml.com

我已经运行这个命令来得到结果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

但是如何提取如下信息:

test@rbl.com
test@pml.com

【问题讨论】:

  • 您使用的是哪个版本的 PowerShell(请参阅$PSVersionTable.PSVersion.Major)?

标签: windows powershell command-line window-server


【解决方案1】:

这应该可以解决问题

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

它会递归地搜索您的文件夹以查找测试文件夹,然后打印出文件夹的父级它​​的父级,以及您希望格式化的文件夹名称。

【讨论】:

  • 反过来。 "{0}@{1}" -f $_.Name,$_.Parent.Parent.Name
  • 我已经运行命令ls test -Directory -Recurse | % { "$($_.Parent.Parent.Name)@$($_.Name)" } 它显示如下输出:airportdirectcabs.com@test aoryxcarrental.ae@test
  • 它工作我通过这种方式运行相同的命令ls test -Directory -Recurse | % { "$($_.Name)@$($_.Parent.Parent.Name)" }
  • 啊,我的错,为了清楚起见,我改为相应地回答
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-08-13
  • 1970-01-01
  • 1970-01-01
  • 2018-12-25
  • 2017-01-09
  • 2011-07-12
  • 2017-04-06
相关资源
最近更新 更多