2016-07-23 43 views
0

我想將一堆子目錄中的文件移動到父目錄中。我已經證實,個人搜索有效,並且我的連接是正確的。然而,移動項目沒有任何東西。Move-Item不移動文件

我不明白爲什麼。

Get-ChildItem $pwd -name -recurse *.docx | foreach{ Move-Item (Join-Path . $_) .} 

任何幫助,將不勝感激。

謝謝。

編輯:根據J.Drexler的解釋/回答更新我的問題特有的解決方案。

Get-ChildItem $pwd -name -recurse *.docx | Move-Item -Destination . 
+1

添加'-whatif'或'-verbose'您移動-Item命令來看看是怎麼回事上。 –

+0

'Move-Item $ _。FullName。\' –

+0

@Mathias R. Jessen:,Get-ChildItem的輸出是一個字符串。所以$ _。FullName將不起作用。 – abjbhat

回答

1

它的完成這樣的:

Get-ChildItem $path -Filter "*.docx" | move-item -Destination (split-path $path -Parent) 

注意:您不需要 「的foreach」 一後 「|」。 如果您使用「|」的列表命令,它同樣喜歡後:

$items = GetList $path 
foreach($item in $items){ DoSomething $item } 

這是一樣的:

GetList $path | DoSomething 
+0

謝謝!因此,參數1是左邊表達式結果的每個項目。瞭解。 – abjbhat