2013-03-12 66 views
2

我有一個文件夾C複製選擇的文件:\圖形(根)和一個程序創建的子文件夾AABMCZXmjpqZZ(這是一個例子,我有很多子文件夾,長度是可變的)。在每個子文件夾中,我有26個文件和一個文件夾。例如,aa文件夾包含:* aa_000.jpg *,* aa_001.jpg *,...,* aa_023.jpg *;其他兩個文件* aa_360.jpg *,aa.html和一個文件夾,路徑完成它是C:\ graphics \ aa \ aa_360。我需要在子文件夾c:\ graphics \ aa \ aa_360中移動24個文件* aa_000.jpg *,* aa_001.jpg *,...,* aa_023.jpg *並且也等於每個子文件夾。其他例子是c:\ graphics \ mjpq \ mjpq_360應該有mjpq_000.jpg,...,mjpq_023.jpg。Powershell的:在子文件夾

我開始腳本,子文件夾思維舉動所有.JPG(25個文件)(後來,我不得不這樣想提取物* xxx_360.jpg *),但不工作:

Get-ChildItem c:\graphics -rec | where-object {$_.extension -match "jpg"} | ForEach-object {$newPath =(Get-Location).toString()+(Get-Location).ToString().SubString(10)+"_360"); Move-Item $_.FullName $newPath} 

但得到 - 找不到文件路徑。 感謝您的高級。

注:我找到了解決方案。工作,但是我發現在控制檯的錯誤:

Get-ChildItem c:\graphics -rec | where-object {$_.extension -match "jpg" -and (!($_.name -like "*360*"))} | ForEach-Object {$newPath =($_.DirectoryName).toString()+($_.DirectoryName).ToString().SubString(10)+"_360"; Move-Item $_.FullName $newPath} 

這是我的第一個PowerShell腳本;)

回答

6

我認爲你可以簡化這個到:

Get-ChildItem c:\graphics -rec *.jpg | Move-Item -Dest {$_.Directory.FullName + "\" + 
    $_.Directory.Name + "_360\" } -WhatIf 

取出-whatif如果建議的移動操作看起來正確。

+0

工作。我發現錯誤,但它的工作。多創建一個文件;)。謝謝 – Todoes 2013-03-12 04:05:42

+0

我認爲你需要Get-ChildItem命令中的-include參數嗎? – Ant 2013-03-22 09:45:57

+0

@Ant按位置使用-filter參數。 – 2013-03-25 16:15:12

相關問題