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
donj
July 15, 2016, 12:22pm
2
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
}
donj
July 15, 2016, 12:41pm
4
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