2

To change the extension of files located at: C:\Users\mohit singh\Desktop\spotlight, I typed the following command in the PowerShell

C:\Users\mohit singh\Desktop\spotlight> ren *.* *.jpg

But I get the following error:

ren : Cannot process argument because the value of argument "path" is not valid. Change the value of the "path"
argument and run the operation again.
At line:1 char:1
+ ren *.* *.jpg
+ ~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Rename-Item], PSArgumentException
    + FullyQualifiedErrorId : Argument,Microsoft.PowerShell.Commands.RenameItemCommand
msanford
  • 11,803
  • 11
  • 66
  • 93
Mohit Singh
  • 143
  • 11
  • Does this answer your question? [How do I change the extension of many files in a directory?](https://stackoverflow.com/questions/12120326/how-do-i-change-the-extension-of-many-files-in-a-directory) – RoadRunner May 13 '20 at 03:19
  • Close Reviewers: I had considered proposing the linked question, but OP's problem is actually a lack of understanding of the different command interpreters on Windows. If desirable, this could be migrated to SuperUser but I leave the decision to collective wisdom. – msanford May 13 '20 at 14:15

1 Answers1

7

You're trying to use the ren command from within PowerShell. However, ren in Powershell is an alias to Rename-Item which is a different command. Powershell and cmd are different shells that use different command interpreters.

Your simplest option is just to run your command from a cmd window, instead of Powershell.

But if you wanted to use Powershell, you can do this by getting every file in the current folder, piping it to Rename-Item, then using the ChangeExtension .Net API to change its extension (which is safer than simple string replacement).

Get-ChildItem -File | Rename-Item -NewName { [io.path]::ChangeExtension($_.Name, "jpg") }

If you want to act on subfolders too, add -Recurse to Get-ChildItem.

msanford
  • 11,803
  • 11
  • 66
  • 93