2012-05-31 15 views
1

我有一個家庭作業問題,我不能得到它的結束:
Write a shell that has two folder names as parameters and moves the second folder as subfolder of the first one and adds '.unu' to all filenames in that second folder.PowerShell的舉動目錄,並添加擴展

這是我寫的,但它不工作:

gci D:\powershell\dir2 | foreach-object{ ren -new ($_.Name + ".unu")} 

Copy-Item -Recurse D:\powershell\dir2.unu D:\powershell\dir2 

Remove-Item -Recurse D:\powershell\dir2.unu 

還可以看到我在D:\powershell 2個文件夾量身定做的,我想你是不是真的用管道在這裏dir1

回答

0

移動dir2 ...:

Move-Item dir3 .\dir1\ -PassThru | Get-ChildItem | 
    where { ! $_.PsIsContainer } | 
    Rename-Item -NewName { $_.Name + ".unu" } 

移動項目將爲您處理移動文件夾,通過PassThru您將獲得新的對象來播放,如果...將它傳送到Get-ChildItem將返回其中的內容(可能考慮在其中添加-recurse。 ..)。 哪裏會過濾掉目錄(只有你被要求重命名文件),Rename-Item會綁定所有文件,並根據請求重命名它們。

有人想寫一個腳本的.. ..? :o