How to scribble a string except for the first character with powershell

How to write a string except for the first character with powershell?

Get-ChildItem -r | Where {!$_.PSIsContainer} | Rename-Item -NewName {$_FullName.substring(0,1).toupper()+$_FullName.substring(1).tolower()}

Failure, fix how?

+3
source share
1 answer

The first problem is that you are missing a point between $_and the property.

The second problem is that the property FullNameis the full path to the object, including the drive and path. Thus, the top stroke of the first character simply makes the drive letter in uppercase (which already was) and nothing changes. Using a property Namewill work as if it has no path at all, and without a path Rename-Itemwill use the path from the original element.

, Get-ChildItem, :

Get-ChildItem -recurse -File |
  Rename-Item -NewName {$_.Name.substring(0,1).toupper()+$_.Name.substring(1).tolower()}

, , . , :

Get-ChildItem -recurse -File |
  Rename-Item -NewName  {(Get-Culture).TextInfo.ToTitleCase($_.Name)}

[Edit] , :

Get-ChildItem -recurse -File | 
    Rename-Item -NewName {(Get-Culture).TextInfo.ToTitleCase($_.BaseName) +
        $_.Extension.ToLower()}
+3

All Articles