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
9
votes
4 answers

In powershell, how can I use Rename-Item to output the old and new file names at the same time?

I'd like to select a list of files using Get-ChildItem piped to Rename-Item and have the output display text with each line showing something like "Renamed oldfilename to newfilename". How can I do this?
James World
  • 29,019
  • 9
  • 86
  • 120
5
votes
1 answer

Rename-item thinks variable is a path

I'm trying to rename a file but powershell thinks my variable is a string and fails. Here is the script: $date=(get-date -Format d) $time=(get-date -Format t) $source = "D:\_qapi.log" $newfilename =…
user3564542
  • 67
  • 1
  • 1
  • 6
4
votes
1 answer

Rename-Item : Source and destination path must be different error in Powershell

I am using Powershell and trying to return the child item of a directory, which happens to be a subdirectory, and then use the Rename-Item cmdlet to rename the subdirectory name to something else. I feel like the following code should…
4
votes
1 answer

Powershell, rename-item doesn't work as expected

I have a bunch of jpg image files named in the following pattern: 0001-rand01_012.jpg 0002-rand03_034.jpg I want to rename them by removing the first 5 characters to get the form: rand01_012.jpg etc.. I use the following command: Get-ChildItem |…
kchak
  • 7,570
  • 4
  • 20
  • 31
3
votes
2 answers

Rename-item: Cannot rename because item at ... does not exist

I am lost with simple rename-item. Need to change names of folders to "01", "02", "03"... Tried everything but at the end I get this "Item doesn't exist". Sorry for dumb question but I am looking for a solution all day. PS C:\Users\admin> $nr =…
Drone_Drone
  • 33
  • 1
  • 3
3
votes
3 answers

++ Operator on Variable Is Not Changing As Expected In ScriptBlock

I am trying to rename files by putting a prefix based on an incrementing counter in the files such as: $directory = 'C:\Temp' [int] $count=71; gci $directory | sort -Property LastWriteTime | ` rename-item -newname {"{0}_{1}" -f $count++, $_.Name}…
ΩmegaMan
  • 29,542
  • 12
  • 100
  • 122
2
votes
2 answers

How to change the file extension of files that contain a certain string with PowerShell

I'm trying to automatically rename all *.txt files to *.log files, but only if they contain the upper case string ERROR. However, the following code doesn't work: Get-ChildItem *.txt -file | Select-String "ERROR" | Rename-Item -NewName { $_.Name…
Nemo XXX
  • 644
  • 2
  • 14
  • 35
2
votes
2 answers

How to batch rename files in PowerShell starting with padded first numbers

I'm a PowerShell newbie so please be gentle! I'm looking to bulk rename a collection of files, then pad the first digits so that they play in order on my devices. For example, I have a folder full of mp3s ABCDEF_S3L1_010221_GHIJK.mp3 through…
MouseMan
  • 23
  • 4
2
votes
3 answers

WindowsPowerShell Rename Item

When I attempt to rename a contracts folder to capitalize the contracts folder I'm receiving an error for renaming it. I've tried "rename-item contracts Contracts" as well. Anyone know if I can force the command or do i need to change my syntax? PS…
2
votes
1 answer

How to move part of a file name to a different position

I have a set of files in a folder. I would like to edit all file names by moving part of the file name to a different position. That is a sample of what I have: Par1_MD_0_5_AL_2_ND_4_Dist_0_Pot_Drop_out.txt …
2
votes
1 answer

Powershell Rename-Item replace multiple naming parameters in one pass

I would like to replace a few filename parameters in one pass. Trying the following results in errors claiming the 'file already exists'. Is there a way to name multiple replace parameters in a single pass? file | Rename-Item -NewName { $_.Name…
Garrett
  • 617
  • 12
  • 30
2
votes
3 answers

Renaming files in directory using new names from csv file

I'm looking for help in creating a script that can rename all of the files contained in a directory to a table referenced in a csv file. For example, I have a folder with random file names and I also have a csv file with the current file names in…
2
votes
1 answer

rename each file with new-guid in powershell

I have been trying to rename each txt file in a folder with the filename $New-Guid.txt, so they should all have unique names. Anyone know the simple way to do this?
Rob F
  • 31
  • 2
2
votes
2 answers

rename parts of a filename in powershell

I have a filename called "Ben_sucksatpowershell_2018_07_13_21_22_07.txt" I'm trying to rename that file to "b.20180713.b" For the script I am writing I need to rename a series of these files, and the new name needs to be based off the original…
freakostudent
  • 105
  • 1
  • 2
  • 9
2
votes
2 answers

Powershell, Rename a directory after parsing and switching strings of its name

So I am trying to rename several level1-subfolders from something like "xy_1234" to "1234_xy". So far I've achieved to split the strings into variables, build the new directory-name and rename the directory, but I'm completely failing, when trying…
1
2 3 4 5 6