使用 Powershell 递归重命名文件 [英] Recursively renaming files with Powershell

查看:62
本文介绍了使用 Powershell 递归重命名文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有一行用于批量重命名我当前所在文件夹中的文件.

I currently have a line to batch rename files in a folder that I am currently in.

dir | foreach { move-item -literal $_ $_.name.replace(".mkv.mp4",".mp4") }

此代码适用于我当前所在的任何目录,但我想要的是从包含 11 个子文件夹的父文件夹运行脚本.我可以通过单独导航到每个文件夹来完成我的任务,但我宁愿运行一次脚本并完成它.

This code works perfectly for whatever directory I'm currently in, but what I want is to run a script from a parent folder which contains 11 child-folders. I can accomplish my task by navigating to each folder individually, but I'd rather run the script once and be done with it.

我尝试了以下方法:

get-childitem -recurse | foreach { move-item -literal $_ $_.name.replace(".mkv.mp4",".mp4") }

有人能在这里指出我正确的方向吗?我对 Powershell 一点也不熟悉,但在这种情况下它满足了我的需求.

Can anyone please point me in the right direction here? I'm not very familiar with Powershell at all, but it suited my needs in this instance.

推荐答案

你已经接近了:

Get-ChildItem -File -Recurse | % { Rename-Item -Path $_.PSPath -NewName $_.Name.replace(".mkv.mp4",".mp4")}

这篇关于使用 Powershell 递归重命名文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆