Powershell. How to parse gci Name? The Next CEO of Stack OverflowParse contig.exe output to *.csv using command-line or PowerShellPowerShell renaming multiple files, specific part of file namePowershell: gci filter with compact outputPowerShell - Changing the PipelineVariable namePowershell parse object / stringParse and Switch Elements of Folder Names using PowershellPowershell Copy-Item recursively but don't include folder nameDirectories containing brackets [ ] in the name being deleted in PowershellPowershell split file name into arraryIn powershell when I call Get-ChildItem or gci, the Mode column forces each item into 2 lines

Solving system of ODEs with extra parameter

No sign flipping while figuring out the emf of voltaic cell?

I believe this to be a fraud - hired, then asked to cash check and send cash as Bitcoin

Is a distribution that is normal, but highly skewed considered Gaussian?

Why doesn't UK go for the same deal Japan has with EU to resolve Brexit?

How to scale a tikZ image which is within a figure environment

Would a grinding machine be a simple and workable propulsion system for an interplanetary spacecraft?

Should I tutor a student who I know has cheated on their homework?

How to sed chunks text from a stream of files from find

Why isn't the Mueller report being released completely and unredacted?

Is there always a complete, orthogonal set of unitary matrices?

"misplaced omit" error when >centering columns

RigExpert AA-35 - Interpreting The Information

Would this house-rule that treats advantage as a +1 to the roll instead (and disadvantage as -1) and allows them to stack be balanced?

Is it ever safe to open a suspicious HTML file (e.g. email attachment)?

Are police here, aren't itthey?

0 rank tensor vs 1D vector

Does increasing your ability score affect your main stat?

Won the lottery - how do I keep the money?

Why don't programming languages automatically manage the synchronous/asynchronous problem?

Why do remote US companies require working in the US?

Help understanding this unsettling image of Titan, Epimetheus, and Saturn's rings?

Newlines in BSD sed vs gsed

Chain wire methods together in Lightning Web Components



Powershell. How to parse gci Name?



The Next CEO of Stack OverflowParse contig.exe output to *.csv using command-line or PowerShellPowerShell renaming multiple files, specific part of file namePowershell: gci filter with compact outputPowerShell - Changing the PipelineVariable namePowershell parse object / stringParse and Switch Elements of Folder Names using PowershellPowershell Copy-Item recursively but don't include folder nameDirectories containing brackets [ ] in the name being deleted in PowershellPowershell split file name into arraryIn powershell when I call Get-ChildItem or gci, the Mode column forces each item into 2 lines










3















# Microsoft Windows [Version 10.0.17134.648] 
# powershell 5.1.17134.48
# dir directory. Include index*,avail* where the last write time is less than
# 4 days. Display a parsed Name. Display the Length and the LastWriteTime.

$time = (Get-Date).AddDays(-4)
gci * -include index*,avail* | where $_.LastWriteTime -gt $time | format-table -HideTableHeaders Name,Length,LastWriteTime


outputs:



available13.html.2019-03-26_081523.bak 93130 3/26/2019 8 : 10 : 05 AM
index.html.2019-03-26_081538.bak 93134 3/26/2019 8 : 15 : 23 AM


I would like to parse Name to this:



available13.html 93130 3/26/2019 8 : 10 : 05 AM
index.html 93134 3/26/2019 8 : 15 : 23 AM


If I use:



$delim = "."
gci * -include *index*,*available13* -Name | `
foreach
$nameArray = $_.Split($delim)
$newName = $nameArray[0] + "." + $nameArray[1]
Write-Output $newName



I get the parsed Name with no date limit, no size and no last write time.



available13.html
available13.html
index.html
index.html


I've tried:



  1. gci | gm | oh -paging

  2. two days of google search

  3. a regex (which I am not proficient at yet)

  4. parse gci outfile

It is close. Do I have to take another approach?










share|improve this question







New contributor




somebadhat is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
























    3















    # Microsoft Windows [Version 10.0.17134.648] 
    # powershell 5.1.17134.48
    # dir directory. Include index*,avail* where the last write time is less than
    # 4 days. Display a parsed Name. Display the Length and the LastWriteTime.

    $time = (Get-Date).AddDays(-4)
    gci * -include index*,avail* | where $_.LastWriteTime -gt $time | format-table -HideTableHeaders Name,Length,LastWriteTime


    outputs:



    available13.html.2019-03-26_081523.bak 93130 3/26/2019 8 : 10 : 05 AM
    index.html.2019-03-26_081538.bak 93134 3/26/2019 8 : 15 : 23 AM


    I would like to parse Name to this:



    available13.html 93130 3/26/2019 8 : 10 : 05 AM
    index.html 93134 3/26/2019 8 : 15 : 23 AM


    If I use:



    $delim = "."
    gci * -include *index*,*available13* -Name | `
    foreach
    $nameArray = $_.Split($delim)
    $newName = $nameArray[0] + "." + $nameArray[1]
    Write-Output $newName



    I get the parsed Name with no date limit, no size and no last write time.



    available13.html
    available13.html
    index.html
    index.html


    I've tried:



    1. gci | gm | oh -paging

    2. two days of google search

    3. a regex (which I am not proficient at yet)

    4. parse gci outfile

    It is close. Do I have to take another approach?










    share|improve this question







    New contributor




    somebadhat is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.






















      3












      3








      3


      0






      # Microsoft Windows [Version 10.0.17134.648] 
      # powershell 5.1.17134.48
      # dir directory. Include index*,avail* where the last write time is less than
      # 4 days. Display a parsed Name. Display the Length and the LastWriteTime.

      $time = (Get-Date).AddDays(-4)
      gci * -include index*,avail* | where $_.LastWriteTime -gt $time | format-table -HideTableHeaders Name,Length,LastWriteTime


      outputs:



      available13.html.2019-03-26_081523.bak 93130 3/26/2019 8 : 10 : 05 AM
      index.html.2019-03-26_081538.bak 93134 3/26/2019 8 : 15 : 23 AM


      I would like to parse Name to this:



      available13.html 93130 3/26/2019 8 : 10 : 05 AM
      index.html 93134 3/26/2019 8 : 15 : 23 AM


      If I use:



      $delim = "."
      gci * -include *index*,*available13* -Name | `
      foreach
      $nameArray = $_.Split($delim)
      $newName = $nameArray[0] + "." + $nameArray[1]
      Write-Output $newName



      I get the parsed Name with no date limit, no size and no last write time.



      available13.html
      available13.html
      index.html
      index.html


      I've tried:



      1. gci | gm | oh -paging

      2. two days of google search

      3. a regex (which I am not proficient at yet)

      4. parse gci outfile

      It is close. Do I have to take another approach?










      share|improve this question







      New contributor




      somebadhat is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.












      # Microsoft Windows [Version 10.0.17134.648] 
      # powershell 5.1.17134.48
      # dir directory. Include index*,avail* where the last write time is less than
      # 4 days. Display a parsed Name. Display the Length and the LastWriteTime.

      $time = (Get-Date).AddDays(-4)
      gci * -include index*,avail* | where $_.LastWriteTime -gt $time | format-table -HideTableHeaders Name,Length,LastWriteTime


      outputs:



      available13.html.2019-03-26_081523.bak 93130 3/26/2019 8 : 10 : 05 AM
      index.html.2019-03-26_081538.bak 93134 3/26/2019 8 : 15 : 23 AM


      I would like to parse Name to this:



      available13.html 93130 3/26/2019 8 : 10 : 05 AM
      index.html 93134 3/26/2019 8 : 15 : 23 AM


      If I use:



      $delim = "."
      gci * -include *index*,*available13* -Name | `
      foreach
      $nameArray = $_.Split($delim)
      $newName = $nameArray[0] + "." + $nameArray[1]
      Write-Output $newName



      I get the parsed Name with no date limit, no size and no last write time.



      available13.html
      available13.html
      index.html
      index.html


      I've tried:



      1. gci | gm | oh -paging

      2. two days of google search

      3. a regex (which I am not proficient at yet)

      4. parse gci outfile

      It is close. Do I have to take another approach?







      powershell






      share|improve this question







      New contributor




      somebadhat is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question







      New contributor




      somebadhat is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question






      New contributor




      somebadhat is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 7 hours ago









      somebadhatsomebadhat

      265




      265




      New contributor




      somebadhat is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      somebadhat is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      somebadhat is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




















          3 Answers
          3






          active

          oldest

          votes


















          3














          I'd use a RegEx with zero length lookbehind assertion to remove everything after html from $_.Name



          This can be done with a calculated property either in a Select-Object or also in a Format-*



          Get-ChildItem -File | 
          Format-Table @n='foo';e=$_.Name -replace '(?<=^.*.html).*$',Name -HideTableHeaders


          Sample output:



          available13.html available13.html.2019-03-26_081523.bak
          index.html index.html.2019-03-26_081538.bak





          share|improve this answer






























            3














            You can add a new property with Add-Member like this



            $time = (Get-Date).AddDays(-4)
            $files = gci * -include index*,avail* | where $_.LastWriteTime -gt $time
            foreach ($f in $files)
            $f
            $files | Format-Table -HideTableHeaders newName,Length,LastWriteTime


            Note that the above snippet assumes that your names always end with .yyyy-mm-dd_iiiiii.bak. If they have some other format then you must include that information in the question, and you may need to use other string methods like replace, substring... to remove the unnecessary part






            share|improve this answer

























            • Although LotPings did not give me what I asked for, his almost solution was closest to what I ultimately needed, a solution that could be corrected into a one line shortcut. Thanks for taking the time. Yours worked right out of the box.

              – somebadhat
              1 hour ago


















            1














            # Microsoft Windows [Version 10.0.17134.648] 
            # powershell 5.1.17134.48
            # parse Notepad++ "backup on save" filenames.
            # dir directory. Include index*,avail* where the last write time is less than
            # 4 days. Display a parsed Name. Display the Length (size) and the LastWriteTime.
            # Can be used as a shortcut: powershell -noexit $time = (Get-Date).AddDays(-4); gci * -include index*,avail* | where $_.LastWriteTime -gt $time | Format-Table @n='foo';e=$_.Name -replace '(?<=^.*.html).*$',Length,LastWriteTime -HideTableHeaders
            # Start it in your directory of choice.

            $time = (Get-Date).AddDays(-4)
            gci * -include index*,avail* | where $_.LastWriteTime -gt $time | Format-Table @n='foo';e=$_.Name -replace '(?<=^.*.html).*$',Length,LastWriteTime -HideTableHeaders


            Expected results:



            available13.html 93130 3/26/2019 8 : 10 : 05 AM
            index.html 39386 3/26/2019 8 : 10 : 05 AM


            Actual results:



            available13.html 93130 3/26/2019 8 : 10 : 05 AM
            index.html 39386 3/26/2019 8 : 10 : 05 AM



            See LotPings answer for the almost solution to the parse:
            "I'd use a RegEx with zero length lookbehind assertion to remove
            everything after html from $_.Name This can be done with a calculated
            property either in a Select-Object or a Format-table". See the corrected solution below.




            | Format-Table @n='foo';e=$_.Name -replace '(?<=^.*.html).*$',Length,LastWriteTime -HideTableHeaders





            share|improve this answer










            New contributor




            somebadhat is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.




















              Your Answer








              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "3"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader:
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              ,
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );






              somebadhat is a new contributor. Be nice, and check out our Code of Conduct.









              draft saved

              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1419414%2fpowershell-how-to-parse-gci-name%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              3














              I'd use a RegEx with zero length lookbehind assertion to remove everything after html from $_.Name



              This can be done with a calculated property either in a Select-Object or also in a Format-*



              Get-ChildItem -File | 
              Format-Table @n='foo';e=$_.Name -replace '(?<=^.*.html).*$',Name -HideTableHeaders


              Sample output:



              available13.html available13.html.2019-03-26_081523.bak
              index.html index.html.2019-03-26_081538.bak





              share|improve this answer



























                3














                I'd use a RegEx with zero length lookbehind assertion to remove everything after html from $_.Name



                This can be done with a calculated property either in a Select-Object or also in a Format-*



                Get-ChildItem -File | 
                Format-Table @n='foo';e=$_.Name -replace '(?<=^.*.html).*$',Name -HideTableHeaders


                Sample output:



                available13.html available13.html.2019-03-26_081523.bak
                index.html index.html.2019-03-26_081538.bak





                share|improve this answer

























                  3












                  3








                  3







                  I'd use a RegEx with zero length lookbehind assertion to remove everything after html from $_.Name



                  This can be done with a calculated property either in a Select-Object or also in a Format-*



                  Get-ChildItem -File | 
                  Format-Table @n='foo';e=$_.Name -replace '(?<=^.*.html).*$',Name -HideTableHeaders


                  Sample output:



                  available13.html available13.html.2019-03-26_081523.bak
                  index.html index.html.2019-03-26_081538.bak





                  share|improve this answer













                  I'd use a RegEx with zero length lookbehind assertion to remove everything after html from $_.Name



                  This can be done with a calculated property either in a Select-Object or also in a Format-*



                  Get-ChildItem -File | 
                  Format-Table @n='foo';e=$_.Name -replace '(?<=^.*.html).*$',Name -HideTableHeaders


                  Sample output:



                  available13.html available13.html.2019-03-26_081523.bak
                  index.html index.html.2019-03-26_081538.bak






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 7 hours ago









                  LotPingsLotPings

                  5,2001823




                  5,2001823























                      3














                      You can add a new property with Add-Member like this



                      $time = (Get-Date).AddDays(-4)
                      $files = gci * -include index*,avail* | where $_.LastWriteTime -gt $time
                      foreach ($f in $files)
                      $f
                      $files | Format-Table -HideTableHeaders newName,Length,LastWriteTime


                      Note that the above snippet assumes that your names always end with .yyyy-mm-dd_iiiiii.bak. If they have some other format then you must include that information in the question, and you may need to use other string methods like replace, substring... to remove the unnecessary part






                      share|improve this answer

























                      • Although LotPings did not give me what I asked for, his almost solution was closest to what I ultimately needed, a solution that could be corrected into a one line shortcut. Thanks for taking the time. Yours worked right out of the box.

                        – somebadhat
                        1 hour ago















                      3














                      You can add a new property with Add-Member like this



                      $time = (Get-Date).AddDays(-4)
                      $files = gci * -include index*,avail* | where $_.LastWriteTime -gt $time
                      foreach ($f in $files)
                      $f
                      $files | Format-Table -HideTableHeaders newName,Length,LastWriteTime


                      Note that the above snippet assumes that your names always end with .yyyy-mm-dd_iiiiii.bak. If they have some other format then you must include that information in the question, and you may need to use other string methods like replace, substring... to remove the unnecessary part






                      share|improve this answer

























                      • Although LotPings did not give me what I asked for, his almost solution was closest to what I ultimately needed, a solution that could be corrected into a one line shortcut. Thanks for taking the time. Yours worked right out of the box.

                        – somebadhat
                        1 hour ago













                      3












                      3








                      3







                      You can add a new property with Add-Member like this



                      $time = (Get-Date).AddDays(-4)
                      $files = gci * -include index*,avail* | where $_.LastWriteTime -gt $time
                      foreach ($f in $files)
                      $f
                      $files | Format-Table -HideTableHeaders newName,Length,LastWriteTime


                      Note that the above snippet assumes that your names always end with .yyyy-mm-dd_iiiiii.bak. If they have some other format then you must include that information in the question, and you may need to use other string methods like replace, substring... to remove the unnecessary part






                      share|improve this answer















                      You can add a new property with Add-Member like this



                      $time = (Get-Date).AddDays(-4)
                      $files = gci * -include index*,avail* | where $_.LastWriteTime -gt $time
                      foreach ($f in $files)
                      $f
                      $files | Format-Table -HideTableHeaders newName,Length,LastWriteTime


                      Note that the above snippet assumes that your names always end with .yyyy-mm-dd_iiiiii.bak. If they have some other format then you must include that information in the question, and you may need to use other string methods like replace, substring... to remove the unnecessary part







                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited 6 hours ago

























                      answered 7 hours ago









                      phuclvphuclv

                      10.5k64295




                      10.5k64295












                      • Although LotPings did not give me what I asked for, his almost solution was closest to what I ultimately needed, a solution that could be corrected into a one line shortcut. Thanks for taking the time. Yours worked right out of the box.

                        – somebadhat
                        1 hour ago

















                      • Although LotPings did not give me what I asked for, his almost solution was closest to what I ultimately needed, a solution that could be corrected into a one line shortcut. Thanks for taking the time. Yours worked right out of the box.

                        – somebadhat
                        1 hour ago
















                      Although LotPings did not give me what I asked for, his almost solution was closest to what I ultimately needed, a solution that could be corrected into a one line shortcut. Thanks for taking the time. Yours worked right out of the box.

                      – somebadhat
                      1 hour ago





                      Although LotPings did not give me what I asked for, his almost solution was closest to what I ultimately needed, a solution that could be corrected into a one line shortcut. Thanks for taking the time. Yours worked right out of the box.

                      – somebadhat
                      1 hour ago











                      1














                      # Microsoft Windows [Version 10.0.17134.648] 
                      # powershell 5.1.17134.48
                      # parse Notepad++ "backup on save" filenames.
                      # dir directory. Include index*,avail* where the last write time is less than
                      # 4 days. Display a parsed Name. Display the Length (size) and the LastWriteTime.
                      # Can be used as a shortcut: powershell -noexit $time = (Get-Date).AddDays(-4); gci * -include index*,avail* | where $_.LastWriteTime -gt $time | Format-Table @n='foo';e=$_.Name -replace '(?<=^.*.html).*$',Length,LastWriteTime -HideTableHeaders
                      # Start it in your directory of choice.

                      $time = (Get-Date).AddDays(-4)
                      gci * -include index*,avail* | where $_.LastWriteTime -gt $time | Format-Table @n='foo';e=$_.Name -replace '(?<=^.*.html).*$',Length,LastWriteTime -HideTableHeaders


                      Expected results:



                      available13.html 93130 3/26/2019 8 : 10 : 05 AM
                      index.html 39386 3/26/2019 8 : 10 : 05 AM


                      Actual results:



                      available13.html 93130 3/26/2019 8 : 10 : 05 AM
                      index.html 39386 3/26/2019 8 : 10 : 05 AM



                      See LotPings answer for the almost solution to the parse:
                      "I'd use a RegEx with zero length lookbehind assertion to remove
                      everything after html from $_.Name This can be done with a calculated
                      property either in a Select-Object or a Format-table". See the corrected solution below.




                      | Format-Table @n='foo';e=$_.Name -replace '(?<=^.*.html).*$',Length,LastWriteTime -HideTableHeaders





                      share|improve this answer










                      New contributor




                      somebadhat is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                      Check out our Code of Conduct.
























                        1














                        # Microsoft Windows [Version 10.0.17134.648] 
                        # powershell 5.1.17134.48
                        # parse Notepad++ "backup on save" filenames.
                        # dir directory. Include index*,avail* where the last write time is less than
                        # 4 days. Display a parsed Name. Display the Length (size) and the LastWriteTime.
                        # Can be used as a shortcut: powershell -noexit $time = (Get-Date).AddDays(-4); gci * -include index*,avail* | where $_.LastWriteTime -gt $time | Format-Table @n='foo';e=$_.Name -replace '(?<=^.*.html).*$',Length,LastWriteTime -HideTableHeaders
                        # Start it in your directory of choice.

                        $time = (Get-Date).AddDays(-4)
                        gci * -include index*,avail* | where $_.LastWriteTime -gt $time | Format-Table @n='foo';e=$_.Name -replace '(?<=^.*.html).*$',Length,LastWriteTime -HideTableHeaders


                        Expected results:



                        available13.html 93130 3/26/2019 8 : 10 : 05 AM
                        index.html 39386 3/26/2019 8 : 10 : 05 AM


                        Actual results:



                        available13.html 93130 3/26/2019 8 : 10 : 05 AM
                        index.html 39386 3/26/2019 8 : 10 : 05 AM



                        See LotPings answer for the almost solution to the parse:
                        "I'd use a RegEx with zero length lookbehind assertion to remove
                        everything after html from $_.Name This can be done with a calculated
                        property either in a Select-Object or a Format-table". See the corrected solution below.




                        | Format-Table @n='foo';e=$_.Name -replace '(?<=^.*.html).*$',Length,LastWriteTime -HideTableHeaders





                        share|improve this answer










                        New contributor




                        somebadhat is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                        Check out our Code of Conduct.






















                          1












                          1








                          1







                          # Microsoft Windows [Version 10.0.17134.648] 
                          # powershell 5.1.17134.48
                          # parse Notepad++ "backup on save" filenames.
                          # dir directory. Include index*,avail* where the last write time is less than
                          # 4 days. Display a parsed Name. Display the Length (size) and the LastWriteTime.
                          # Can be used as a shortcut: powershell -noexit $time = (Get-Date).AddDays(-4); gci * -include index*,avail* | where $_.LastWriteTime -gt $time | Format-Table @n='foo';e=$_.Name -replace '(?<=^.*.html).*$',Length,LastWriteTime -HideTableHeaders
                          # Start it in your directory of choice.

                          $time = (Get-Date).AddDays(-4)
                          gci * -include index*,avail* | where $_.LastWriteTime -gt $time | Format-Table @n='foo';e=$_.Name -replace '(?<=^.*.html).*$',Length,LastWriteTime -HideTableHeaders


                          Expected results:



                          available13.html 93130 3/26/2019 8 : 10 : 05 AM
                          index.html 39386 3/26/2019 8 : 10 : 05 AM


                          Actual results:



                          available13.html 93130 3/26/2019 8 : 10 : 05 AM
                          index.html 39386 3/26/2019 8 : 10 : 05 AM



                          See LotPings answer for the almost solution to the parse:
                          "I'd use a RegEx with zero length lookbehind assertion to remove
                          everything after html from $_.Name This can be done with a calculated
                          property either in a Select-Object or a Format-table". See the corrected solution below.




                          | Format-Table @n='foo';e=$_.Name -replace '(?<=^.*.html).*$',Length,LastWriteTime -HideTableHeaders





                          share|improve this answer










                          New contributor




                          somebadhat is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.










                          # Microsoft Windows [Version 10.0.17134.648] 
                          # powershell 5.1.17134.48
                          # parse Notepad++ "backup on save" filenames.
                          # dir directory. Include index*,avail* where the last write time is less than
                          # 4 days. Display a parsed Name. Display the Length (size) and the LastWriteTime.
                          # Can be used as a shortcut: powershell -noexit $time = (Get-Date).AddDays(-4); gci * -include index*,avail* | where $_.LastWriteTime -gt $time | Format-Table @n='foo';e=$_.Name -replace '(?<=^.*.html).*$',Length,LastWriteTime -HideTableHeaders
                          # Start it in your directory of choice.

                          $time = (Get-Date).AddDays(-4)
                          gci * -include index*,avail* | where $_.LastWriteTime -gt $time | Format-Table @n='foo';e=$_.Name -replace '(?<=^.*.html).*$',Length,LastWriteTime -HideTableHeaders


                          Expected results:



                          available13.html 93130 3/26/2019 8 : 10 : 05 AM
                          index.html 39386 3/26/2019 8 : 10 : 05 AM


                          Actual results:



                          available13.html 93130 3/26/2019 8 : 10 : 05 AM
                          index.html 39386 3/26/2019 8 : 10 : 05 AM



                          See LotPings answer for the almost solution to the parse:
                          "I'd use a RegEx with zero length lookbehind assertion to remove
                          everything after html from $_.Name This can be done with a calculated
                          property either in a Select-Object or a Format-table". See the corrected solution below.




                          | Format-Table @n='foo';e=$_.Name -replace '(?<=^.*.html).*$',Length,LastWriteTime -HideTableHeaders






                          share|improve this answer










                          New contributor




                          somebadhat is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.









                          share|improve this answer



                          share|improve this answer








                          edited 1 hour ago





















                          New contributor




                          somebadhat is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.









                          answered 1 hour ago









                          somebadhatsomebadhat

                          265




                          265




                          New contributor




                          somebadhat is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.





                          New contributor





                          somebadhat is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.






                          somebadhat is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.




















                              somebadhat is a new contributor. Be nice, and check out our Code of Conduct.









                              draft saved

                              draft discarded


















                              somebadhat is a new contributor. Be nice, and check out our Code of Conduct.












                              somebadhat is a new contributor. Be nice, and check out our Code of Conduct.











                              somebadhat is a new contributor. Be nice, and check out our Code of Conduct.














                              Thanks for contributing an answer to Super User!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid


                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.

                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1419414%2fpowershell-how-to-parse-gci-name%23new-answer', 'question_page');

                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Are there any AGPL-style licences that require source code modifications to be public? Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?Force derivative works to be publicAre there any GPL like licenses for Apple App Store?Do you violate the GPL if you provide source code that cannot be compiled?GPL - is it distribution to use libraries in an appliance loaned to customers?Distributing App for free which uses GPL'ed codeModifications of server software under GPL, with web/CLI interfaceDoes using an AGPLv3-licensed library prevent me from dual-licensing my own source code?Can I publish only select code under GPLv3 from a private project?Is there published precedent regarding the scope of covered work that uses AGPL software?If MIT licensed code links to GPL licensed code what should be the license of the resulting binary program?If I use a public API endpoint that has its source code licensed under AGPL in my app, do I need to disclose my source?

                              2013 GY136 Descoberta | Órbita | Referências Menu de navegação«List Of Centaurs and Scattered-Disk Objects»«List of Known Trans-Neptunian Objects»

                              Button changing it's text & action. Good or terrible? The 2019 Stack Overflow Developer Survey Results Are Inchanging text on user mouseoverShould certain functions be “hard to find” for powerusers to discover?Custom liking function - do I need user login?Using different checkbox style for different checkbox behaviorBest Practices: Save and Exit in Software UIInteraction with remote validated formMore efficient UI to progress the user through a complicated process?Designing a popup notice for a gameShould bulk-editing functions be hidden until a table row is selected, or is there a better solution?Is it bad practice to disable (replace) the context menu?