[英]Renaming files in powershell using the folder name
Using Powershell, I want to rename files in folders by using the name of the folder that the files are in. So in my C:\\temp directory, there are 3 folders called 'aaa', 'bbb' and 'ccc'.使用 Powershell,我想通过使用文件所在文件夹的名称来重命名文件夹中的文件。所以在我的 C:\\temp 目录中,有 3 个文件夹分别称为“aaa”、“bbb”和“ccc”。 In each of these folders, there are 3 files called doc1.txt, doc2.txt and doc3.txt.
在每个文件夹中,有 3 个文件,分别称为 doc1.txt、doc2.txt 和 doc3.txt。 I would like to rename all 9 .txt files to folderName+fileName, so they would be renamed to the following:
我想将所有 9 个 .txt 文件重命名为 folderName+fileName,因此它们将重命名为以下内容:
aaadoc1.txt
aaadoc2.txt
aaadoc3.txt
bbbdoc1.txt
bbbdoc2.txt
bbbdoc3.txt
cccdoc1.txt
cccdoc2.txt
cccdoc3.txt
这将重命名文件并在文件夹名称和文件名之间加上下划线('_'):
Get-ChildItem C:\temp -Filter *.txt -Recurse | Rename-Item -NewName { $_.Directory.Name+'_'+$_.Name}
[IO.Directory]::GetCurrentDirectory().split('\\\\')[-1]
将为您提供所在的目录。
Try this 尝试这个
$dirname = resolve-path . | split-path -leaf
Get-ChildItem -Name | Foreach { Rename-Item $_ ( $dirname + $_ ) }
Be careful not to destroy/delete any of your files. 小心不要销毁/删除任何文件。 No guarantee.
不保证。
Is it possible to run on utorrent?是否可以在utorrent上运行? To rename inside files of a folder to its folder name when a torrent is finished downloading
在种子下载完成后将文件夹的内部文件重命名为其文件夹名称
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.