选定字符串上的拆分路径

时间:2017-01-13 02:47:37

标签: powershell

基本上我希望下面我可以生成的所有信息都在同一个变量中。目前我有2件。我想将Split-Path的输出作为标题为"文件夹"的新列。在$newdata变量中。

$newdata = gci -r C:\temp\Screenshots\*.* |
           ? {$_.LastWriteTime -gt '12/30/16'} |
           % {Get-ItemProperty $_} |
           select BaseName, Directory

$newdata | select Directory | % {
  Split-Path (Split-Path "$_" -Parent) -Leaf
}

1 个答案:

答案 0 :(得分:2)

那是calculated properties的用途。

$newdata = Get-ChildItem -Recurse C:\temp\Screenshots\*.* |
           Where-Object {$_.LastWriteTime -gt '12/30/16'} |
           ForEach-Object {Get-ItemProperty $_} |
           Select-Object BaseName, Directory,
             @{n='Folder';e={Split-Path $_.Directory -Parent | Split-Path -Leaf}}