Jiawei
Jiawei

Reputation: 13

PowerShell Change File Extension

Changing file extension of files in a folder if the file was created yesterday.

This is to change the file extension path from .comh to .txt

if ($countFiles.Count -gt 0)

    {

    foreach ($f in $files)

      {

     if ($f.CreationTime -gt($(Get-Date).AddDays((-1))))

      {
        #Changing of extension      
      }  

Upvotes: 1

Views: 9679

Answers (1)

Prasoon Karunan V
Prasoon Karunan V

Reputation: 3043

You'll get all the properties of that file in $f , use Rename-Item cmdlet to rename it, you would build the new name from the existing by changing the extension.

#Changing of extension
$NewName = $F.BaseName + '.txt'
$F | Rename-Item -NewName $NewName

Upvotes: 2

Related Questions