Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This would handle any number of underscores in filename (ignoring the path) and skip everything up to and including the last underscore when generating new name:-</p> <pre><code>Get-ChildItem 'C:\somedir' -Filter *.pdf |` %{Rename-Item $_.Fullname ($_.Name.Split("_")|` select -last 1)} </code></pre> <p>You can test using the -whatif switch on the rename-item command e.g</p> <pre><code>gci 'R:\TECH' -Filter *.pdf|` %{rename-item -whatif $_.Fullname ($_.Name.Split("_")|` select -last 1)} </code></pre> <p>Returns:</p> <p>What if: Performing operation "Rename File" on Target "Item: R:\TECH\38415_JOBS121121155535240.pdf Destin ation: R:\TECH\JOBS121121155535240.pdf". What if: Performing operation "Rename File" on Target "Item: R:\TECH\CHG38415_JOB_121112153717550.pdf Des tination: R:\TECH\121112153717550.pdf". What if: Performing operation "Rename File" on Target "Item: R:\TECH\CHG38415_PREH_121113152548740.pdf De stination: R:\TECH\121113152548740.pdf". What if: Performing operation "Rename File" on Target "Item: R:\TECH\CHG38415_PREI_121113152600640.pdf De stination: R:\TECH\121113152600640.pdf". What if: Performing operation "Rename File" on Target "Item: R:\TECH\MCPTEST121125121201390.pdf Destinati on: R:\TECH\MCPTEST121125121201390.pdf". What if: Performing operation "Rename File" on Target "Item: R:\TECH\PREHAND_38415_121121154127000.pdf De stination: R:\TECH\121121154127000.pdf". What if: Performing operation "Rename File" on Target "Item: R:\TECH\PREIMP_38415_121121154140630.pdf Des tination: R:\TECH\121121154140630.pdf".</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload