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.

这是我写的,但它不起作用:

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:\powershell2 个文件夹中制作,我想搬进dir2dir1

4

1 回答 1

0

你在这里并没有真正使用管道......:

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

Move-item 将为您处理移动文件夹,如果使用 PassThru,您将获得要播放的新对象... 将其传送到 Get-ChildItem 将返回其中的内容(可以考虑在其中添加 -recurse ...)。Where 将过滤掉目录(仅要求您重命名文件),并且 Rename-Item 将绑定所有文件,并根据要求重命名它们。

有人想为此写一个脚本..?:o

于 2012-05-31T07:40:19.043 回答