Renaming Logfiles

Tagged: 

This topic contains 5 replies, has 3 voices, and was last updated by Profile photo of Edmond Yee Edmond Yee 2 months, 1 week ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #47109
    Profile photo of Venkata Kalyan
    Venkata Kalyan
    Participant

    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

    #47113
    Profile photo of Don Jones
    Don Jones
    Keymaster

    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?

    #47117
    Profile photo of Venkata Kalyan
    Venkata Kalyan
    Participant

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

    }

    #47119
    Profile photo of Don Jones
    Don Jones
    Keymaster

    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.

    #47121
    Profile photo of Venkata Kalyan
    Venkata Kalyan
    Participant

    Yes, same file. Thanks. Will check out.

    -Kalyan

    #47511
    Profile photo of Edmond Yee
    Edmond Yee
    Participant

    This page also has background information for Rename-Item

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

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.