Forum Discussion
Change file extensions
- Sep 14, 2024
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
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
- derekman1Sep 15, 2024Copper ContributorSorry for the vagueness. This worked perfectly! Thank you!