Author Posts

July 15, 2016 at 5:49 pm

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

July 15, 2016 at 5:52 pm

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?

July 15, 2016 at 6:05 pm

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

}

July 15, 2016 at 6:11 pm

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.

July 15, 2016 at 6:13 pm

Yes, same file. Thanks. Will check out.

-Kalyan