Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>When you use <code>Rename-item $_</code> your sending setting the 1st positional parameter, <code>-Path</code>, equal to <code>$_</code> casted as a string(which will be the filename). The problem with <code>-Path</code> is that it doesn't support special characters very vell, which I'm guessing you have in your filename.</p> <p>If you had used <code>$_ | Rename-Item</code>, the cmdlet would have linked up the <code>FullName</code> property with <code>-LiteralPath</code> parameter in the cmdlet. <code>-LiteralPath</code> is an alternative to <code>-Path</code> which works better with special characters, and because of that it's used as default for parameter-binding in pipelines.</p> <p>By using the approach below, we will tell your script to use <code>-LiteralPath</code> and link it with the full path of the file, <code>FullName</code>, which should solve your problems. This is the recommended way to use the cmdlet if you're using a foreach-loop instead of <code>Get-ChildItem | Rename-Item</code>.</p> <p>Also, if you want all files in a folder, you don't need to use filter. Try the sample below.</p> <pre><code>$i = 1 cd "C:\Users\myname\Desktop\test" get-childitem | %{ Rename-Item -LiteralPath $_.FullName -NewName ("filename_s01e{0:D3}.lnk" -f $i++) } </code></pre> <p>You could also include the folderpath in the <code>Get-ChildItem</code> cmdlet and create your variable in the foreach-loop like:</p> <pre><code>Get-ChildItem -Path "C:\Users\myname\Desktop\test" | % -Begin { $i = 1 } -Process { Rename-Item -LiteralPath $_.FullName -NewName ("filename_s01e{0:D3}.lnk" -f $i++) } </code></pre>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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