Forum Discussion
Change file extensions
I have a folder with thousands of files all of which have different extensions. I need to change all the extensions to "jpg" and looked at Rename and replace, but since every extension is different I cannot provide all for the replace function. Sounds weird but the files were produced by a vendors application and all extensions are numeric, "001", "002", "003" and on.
Any help would be appreciated.
Hi, David.
I'm unclear on whether you're working in a single directory or a directory tree. I'm also unclear on whether or not there are other files within these directory(ies) that you do not want renamed.
For the sake of simplicity, I'm going to assume that:
- All files exist within the same directory (i.e. not child directories);
- All files in that directory are going to have their extension renamed.
If these assumptions are incorrect, please provide more detail on the scenario.
In this assumed scenario, a single, simple command can rename everything to have the extension of .jpg:
(Get-ChildItem -File -Path "C:\Data\Temp\*") | ForEach-Object { Rename-Item -Path $_.FullName -NewName "$($_.BaseName).jpg" };
Here's an illustrated example, where I first show a few properties of a file I intend to rename (I'm not looking to rename every file this example as I have items I don't want renamed), then rename the shown file before finally running another check on the file to illustrate how the properties have change when compared to the first command.
Cheers,
Lain
- LainRobertsonSilver Contributor
Hi, David.
I'm unclear on whether you're working in a single directory or a directory tree. I'm also unclear on whether or not there are other files within these directory(ies) that you do not want renamed.
For the sake of simplicity, I'm going to assume that:
- All files exist within the same directory (i.e. not child directories);
- All files in that directory are going to have their extension renamed.
If these assumptions are incorrect, please provide more detail on the scenario.
In this assumed scenario, a single, simple command can rename everything to have the extension of .jpg:
(Get-ChildItem -File -Path "C:\Data\Temp\*") | ForEach-Object { Rename-Item -Path $_.FullName -NewName "$($_.BaseName).jpg" };
Here's an illustrated example, where I first show a few properties of a file I intend to rename (I'm not looking to rename every file this example as I have items I don't want renamed), then rename the shown file before finally running another check on the file to illustrate how the properties have change when compared to the first command.
Cheers,
Lain
- derekman1Copper ContributorSorry for the vagueness. This worked perfectly! Thank you!