我有一個場景,我需要搜索檔案夾和子檔案夾的某些檔案型別。如果找到這些型別,那么整個根檔案夾和所有檔案及子檔案夾都需要被移動。
來源 c: estsource 例如:搜索*.exe檔案 發現以下檔案 c: estsourcefolder1subfolder1 estfile.exe 那么檔案夾1以及所有的檔案和子檔案夾需要被移動到c: estdestination
。我首先用一個批處理檔案試了一下,能夠移動子檔案夾1中的所有檔案,但沒有移動任何其他檔案或目錄結構。然后我開始在 powershell 中作業,但有類似的結果。我想我需要的是搜索,如果發現捕獲檔案夾路徑,然后移動該檔案夾,但不確定如何做到這一點。
我創建的批處理檔案:
for /r "C:TestSource" %i in (*. exe)do move "%~dpi*" "C:TestDestination"
Powershell腳本
$Source = "C:estsource"
$Dest = "C: estdestination"
Get-ChildItem -Recurse -Path $Source | Where {$_. fullname -Match '.*.exe'}。| Move-Item -Destination $Dest
如果有任何幫助,我們將非常感激
uj5u.com熱心網友回復:
你將需要一個回圈來檢查源檔案夾的每個直接子檔案夾,如果它在其中的一個子檔案夾中擁有所需的檔案。 ...像這樣:
$Source = 'C: estsource'
$Dest = 'C: estdestination'。
Get-ChildItem -Path $Source -Directory !
ForEach-Object{
If (Get-ChildItem -Path $_.FullName -Recurse -File -Filter '*.exe' /span>){
Move-Item -Path $_.FullName -Destination $Dest -Recurse
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/307955.html
標籤:
