简体   繁体   English

Powershell用父文件夹名称替换文件名而不更改文件结尾

[英]Powershell replacing filenames with parent folder name without changing file endings

I have a parent folder with over 1000 level 1 nested folders and thousands of text files inside each folder: 我有一个父文件夹,其中包含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

I need to be able to rename the files with PowerShell as follows: 我需要能够使用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

Is there a way of doing this in PowerShell, Windows Server 2012 有没有一种方法可以在Windows Server 2012 PowerShell中进行

Thank you ahead of time. 提前谢谢你。

dir C:\temp\folder\ -directory | % {dir $_.fullname | % {ren $_.fullname $((split-path (split-path $_.fullname) -leaf) + '_' + $_.name)}}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Powershell:删除父文件夹名称不同的文件夹中的文件 - Powershell: Delete a file inside a folder with different name of parent folder Powershell - 从文件名创建文件夹,然后将该文件放在该文件夹中 - Powershell - Create a folder from a file name, then place that file in the folder 替换* .zip文件中的文件而不在Powershell中解压缩(解压缩) - Replacing files in a *.zip file without unzipping (extracting) in Powershell powershell - 读取文件夹中的所有.sql 文件并将它们全部保存到单个.sql 文件中,无需更改换行符或换行符 - powershell - read all .sql files in a folder and save them all into a single .sql file without changing line ends or line feeds 将当前日期添加或替换为文件或文件夹名称的末尾 - Adding or replacing the current date to the end of a file or folder name 更改文件夹名称,matlab - changing folder name, matlab C#用“”替换包含“。”的文件名,但删除文件扩展名 - C# Replacing filenames containing “.” with “ ” but removing the file extension Powershell中的文件和文件夹操作 - File and Folder Manipulation in Powershell 如何在不更改文件类型的情况下更改文件名? - How can I change a file name without changing the file type? 循环浏览文件夹中的excel文件并打开它而不参考文件名 - Loop through excel files in a folder and open it without reference to filenames
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM