Renaming Logfiles

Hi,
I have few logfiles (NOTE: these lofile names will be changing). I need to rename or convert those logfiles names to standard names.

Ex:
u_ex010203.log
u_ex010204.log

NOTE: Above logfiles name will be changing based upon the dates.

I need to convert like - 1.log, 2.log…

-Kalyan

Since our goal here is to help you, rather than produce a complete solution for you, can you share what you’ve already tried, or ask a specific question about where you’re stuck?

Hi,
Below is the code:
Get-ChildItem “C:\Users\admin\Documents\My” -Filter *.log |
Foreach-Object {
$content = Get-Content $.FullName
$content | Set-Content $
.FullName

}

OK, so $_ is the file itself. You can certainly rename it.

$_ | Rename-Item -New whatever.txt

You obviously need to come up with the new name, for example, if you just want them sequential

$new = 0
Get-ChildItem "C:\Users\admin\Documents\My" -Filter *.log |
Foreach-Object {
 $content = Get-Content $_.FullName
 $content | Set-Content $_.FullName
 $_ | Rename-Item -New "$new.log"
 $new++
}

Or something like that, I think will be close to what you want.

Yes, same file. Thanks. Will check out.

-Kalyan

This page also has background information for Rename-Item

https://technet.microsoft.com/en-us/library/206faab9-cadb-4daf-b5fd-2af9dcbd6b10