我需要移動很多子檔案夾。每個客戶端都有這個結構,需要修改
我需要移動的唯一檔案夾是“ Correspondence ”檔案夾及其所有內容。它需要“上升”一級到與“2022”檔案夾相同的級別
當前檔案夾結構如下所示:
客戶
............姓氏,姓名縮寫
......................2022,往年
...... ..................................................... .............2018 年
.................................... ......................2019 年
...................... ................................................2020
.... .....................................................
………………………………………………………………………… 2021 ......................計算
...................... ...................................通信
這就是我需要的
客戶
===>姓氏,姓名縮寫
===>2022, 通信,往年
................................................ ......................................2018 年
...... .....................................................
………………………………………… 2019 ..................................2020
...... ..................................................... .....2021
...................................... .........................計算
這是我嘗試過的
dir -Directory | % {Push-Location $_.FullName; dir './Correspondence' | % {Move-Item $_.FullName} 但這不起作用并導致錯誤
dir -Directory | % {Push-Location $_.FullName; dir './Correspondence' | % {Move-Item $_.FullName} 這也導致了錯誤
uj5u.com熱心網友回復:
以下內容定位Correspondence在當前目錄的子樹中命名的所有子目錄并將它們上移一級:
(Get-ChildItem -Recurse -Directory -Filter 'Correspondence') |
Move-Item -Destination { $_.Parent.Parent.FullName } -WhatIf
注意:上面命令中的-WhatIf常用引數是預覽操作。-WhatIf 一旦您確定該操作將執行您想要的操作,請洗掉。
筆記:
Get-ChildItem呼叫包含在內,以便預先收集其(...)所有輸出,以排除移動操作干擾檔案系統項列舉的可能性。-Destination引數以延遲系結腳本塊的形式提供,它允許從手頭的輸入物件派生引數值,反映在自動$_變數中:輸出的instances的
.Parent屬性反映了父目錄(作為同型別的實體),即子目錄hand當前所在的目錄。System.IO.DirectoryInfoGet-ChildItem.Parent.Parent因此反映了子目錄當前所在目錄的父目錄,并且.FullName屬性包含其完整路徑。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/462233.html
標籤:电源外壳
