我有一个父文件夹,每个文件夹中有超过1000个1级嵌套文件夹和数千个文本文件:
Parent folder ==> Folder1 ==> File1.txt
Parent folder ==> Folder1 ==> File2.txt
Parent folder ==> Folder1 ==> File3.txt
Parent folder ==> Folder2 ==> File1.txt
Parent folder ==> Folder2 ==> File2.txt
Parent folder ==> Folder2 ==> File3.txt
Parent folder ==> Folder3 ==> File1.txt
Parent folder ==> Folder3 ==> File2.txt
Parent folder ==> Folder3 ==> File3.txt
我需要能够使用PowerShell重命名文件,如下所示:
Parent folder ==> Folder1 ==> Folder1_File1.txt
Parent folder ==> Folder1 ==> Folder1_File2.txt
Parent folder ==> Folder1 ==> Folder1_File3.txt
Parent folder ==> Folder2 ==> Folder2_File1.txt
Parent folder ==> Folder2 ==> Folder2_File2.txt
Parent folder ==> Folder2 ==> Folder2_File3.txt
Parent folder ==> Folder3 ==> Folder3_File1.txt
Parent folder ==> Folder3 ==> Folder3_File2.txt
Parent folder ==> Folder3 ==> Folder3_File3.txt
有没有办法在PowerShell,Windows Server 2012中执行此操作
提前谢谢你。
答案 0 :(得分:0)
dir C:\temp\folder\ -directory | % {dir $_.fullname | % {ren $_.fullname $((split-path (split-path $_.fullname) -leaf) + '_' + $_.name)}}