I have few logfiles (NOTE: these lofile names will be changing). I need to rename or convert those logfiles names to standard names.
NOTE: Above logfiles name will be changing based upon the dates.
I need to convert like - 1.log, 2.log…
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?
Below is the code:
Get-ChildItem “C:\Users\admin\Documents\My” -Filter *.log |
$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 |
$content = Get-Content $_.FullName
$content | Set-Content $_.FullName
$_ | Rename-Item -New "$new.log"
Or something like that, I think will be close to what you want.
Yes, same file. Thanks. Will check out.