Questions tagged [rename-item-cmdlet]

Rename an item (a folder or a file) using rename-item powershell cmdlet

Rename-Item is used to rename a file or a folder. Takes two parameters -

  • Current Full path of the file/folder
  • New name

    Rename-Item "C:\My Documents\test.txt" new_test.txt

The aliases "rni" and "ren" also have the same affect.

83 questions
2
votes
1 answer

Rename-Item : add unique numeric sequence to prevent duplicate file names

I need a way to rename files in a directory that would result in an error with a simple Rename-Item. The files need the same 10 digit code followed by 4 digit place holder (numbers only please). Current file…
Garrett
  • 617
  • 12
  • 30
2
votes
2 answers

Powershell Script to replace characters in path strings errors out due to "(" or ")"

I have written a Powershell script that receives N number of characters that have to be replaced by another given character from a user. For example, the user wants to replace (, ), and -. The user enters the characters that have to be replaced…
Andrew
  • 23
  • 5
2
votes
5 answers

Adding leading zeros to file name strings using PowerShell

I'm new to using PowerShell and am wondering how to simply pad number strings contained in several similar file names to have the same number of digits in each file name. That is, I have a folder containing these 300 files: dummy name 1.txt through…
D. Whittaker
  • 31
  • 1
  • 3
2
votes
1 answer

One Line PowerShell Batch Rename based on File Contents

I have a list of EDI text files with specific text in them. Currently in order for our custom scripting to convert them into an SQL table, we need to be able to see the X12 file type in the filename. Because we are using SQL script to get the files…
willm
  • 25
  • 6
2
votes
1 answer

Batch file & folder renaming in Windows Powershell

I have hundred thousands files located in ~40 folders (these subfolders being located in a same super-folder which I am going to call 'test'). I have tried to use powershell to replace a syntax found in the folder name but also in the…
Rhiz
  • 23
  • 6
2
votes
2 answers

PowerShell: Rename multiple folders using $_.FullName.Replace

I have a google drive folder that occasionally gets out of sync. Google (or someone) will append (1) to the directory/file names. Then it will remove the original directory and I'll have a bunch of folders and files named "xxx (1)". I've been…
rMa
  • 79
  • 1
  • 9
2
votes
1 answer

powershell rename-item replace with variables incrementing

I'm trying to use the output of a Get-Childitem | Where-Object to rename a group of files but instead of rename with a constant name I want to rename with a group of variables, and I'm use the operator -replace to find where in the string is what I…
WFS
  • 23
  • 4
2
votes
1 answer

Rename Proposition to end of directory title

I have to change the name of approximately 600 directories to conform with the the business naming standards and it is proving to be quite complicated. I will present the problem in a music directory format because it will be easier to explain and…
Dheebs
  • 398
  • 1
  • 6
  • 19
2
votes
1 answer

Error when I want to rename the files generated in a for loop in powerShell

Here is my for loop function Generate_bin($input_1, $bin_file_name, $Codes){ $counter=1 foreach ($Code in $Codes) { Write-Host "Code = $Code" $input_11 = "$input_1" + "$counter" $pattern = "0x" $New = "" …
2
votes
0 answers

How to read meta data of an epub with XmlReader and DeflateStream in a powershell Cmdlet

I've tried to write a commandlet for getting meta information from an epub file. I would like to use the commandlet like this: Get-ChildItem '*.epub' | Get-EpubMetaInfo | %{ Rename-Item $_.File "$($_.Author) - $($_.Title).epub" } So…
Mattia72
  • 825
  • 1
  • 8
  • 23
2
votes
1 answer

Cannot Bind Argument to Parameter 'NewName' because it is an empty string

Get-ChildItem -Name *.txt | Rename-Item -NewName { $_.name -replace '\.txt','.log' } I have 3 text files in my current path, I'm using this snip bit of code found in the last example of... get-help rename-item -full (Powershell Version 2.0). For…
JoeDaHobo
  • 25
  • 1
  • 1
  • 5
2
votes
2 answers

PowerShell complaining about path, But path is valid

In the following code, when $client = XRS1 if (Test-Path C:\dbbackups\cm_$client-*.full.bak){ Rename-Item -path C:\dbbackups\cm_$client-*.bak -newname cm_$client.bak Write-Host "New file found, renamed to: cm_$client.bak" The Test-Path statement…
CryptoJones
  • 734
  • 3
  • 11
  • 33
2
votes
2 answers

PowerShell command to insert 1 character in the middle of a filename

Have a directory of images named like IMG_xxxx.JPG, where x is an integer. I need to insert a "1" after the underscore, so each name becomes IMG_1xxxx.JPG. I tried this in PowerShell: Dir | Rename-Item -NewName { $_.name -replace "_","_1" } and it…
Sapphireblue
  • 104
  • 2
  • 15
1
vote
1 answer

PowerShell optimize Rename-Item -NewName using Split method

In short I'm inserting a hardcoded value 'USA' into the middle of the file name. My code currently works however I feel like it could be optimized, maybe by using -replace operator and RegEx or less returned values (everything before the 4th…
1
vote
3 answers

Rename files by the third delimiter from the end of the name

I have a PowerShell code that renaming the files name, and just cutting some letters from the end of the file name. Now I am trying to rename it like this: For example my file name is "a_b_c_d_e_f.txt", so I want to change it to "a_b_c.txt". Any…
David
  • 239
  • 1
  • 2
  • 12