使用powershell将文件名中每个单词的首字母大写 [英] Capitalize the first letter of each word in a filename with powershell

查看:218
本文介绍了使用powershell将文件名中每个单词的首字母大写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想自动更改某些文件的名称。

I want to change the names of some files automatically.

使用此代码,我将小写字母更改为大写:

With this code I change the lowercase letters to uppercase:


get-childitem * .mp3 | foreach {if($(em).Name -cne $ .Name.ToUpper()){
ren $ .FullName $ .Name.ToUpper()}}

get-childitem *.mp3 | foreach { if ($.Name -cne $.Name.ToUpper()) { ren $.FullName $.Name.ToUpper() } }

但是我只希望每个单词的首字母大写。

But I only want the first letter of each word to be uppercase.

推荐答案

您可以使用 ToTitleCase 方法:

You can use ToTitleCase Method:

$TextInfo = (Get-Culture).TextInfo
$TextInfo.ToTitleCase("one two three")

输出


一二三

One Two Three



$TextInfo = (Get-Culture).TextInfo
get-childitem *.mp3 | foreach { $NewName = $TextInfo.ToTitleCase($_); ren $_.FullName $NewName }

这篇关于使用powershell将文件名中每个单词的首字母大写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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