93

Changing file types all with different extensions to one single extension : Powe...

 6 years ago
source link: https://www.reddit.com/r/PowerShell/comments/7iw8ny/changing_file_types_all_with_different_extensions/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Posted by5 years ago

Changing file types all with different extensions to one single extension

Basically I got a ton of files that stupidly enough were all named ending with:

._(01)
._(02)
._(03)
._(04)

This basically carries on into the hundreds meaning every single file is a different file type and carries a different extension that goes up by a single digit each time.

And as a result the only way to open any one of these files is to manually rename each one of them one by one adding the correct extension (.png)

I've tried a couple different types of software but each one forces me to to manually add the hundreds of different types of extensions that I want to change meaning I might as well just rename them to begin with making the software pretty useless in my scenario.

I'm not so clued up on my commands besides the basic directory stuffs and a little troubleshooting (CD, DIR, FDISK, CHKDSK, IPCONFIG Etc.) so perhaps someone here could recommend a command that allows me to change every single extension regardless of the type in my active directory to a single extension.

Thanks fellas :)

71% Upvoted
level 1
· 5 yr. ago · edited 5 yr. agoCommunity Blogger

I think we are over thinking this.

Get-ChildItem -exclude *.png | Foreach-Object{
    Rename-Item -Path $_.FullName -NewName "$($_.fullname).png"
}

Just add png to all the files.

Edit: I fixed the typo that /u/ka-splam pointed out

level 2

You're right about the overthinking, double extensions are perfectly acceptable

level 2
Comment deleted by user · 5 yr. ago
level 1

Easiest way would be if they are all in the same path... Typing this on my phone so bear with me

Get-childitem -file -literalpath "\\path\to\files" | foreach-object {$_ | rename-item -newname "$($_.basename).png"}

Edit: To add the new extension instead of dealing with modifying the old extension, change "basename" to "fullname" Get-childitem -file -literalpath "\\path\to\files" | foreach-object {$_ | rename-item -newname "$($_.FullName).png"}

level 2

Thanks a bunch for the response, Seems to have worked in changing one of the files however I get the following error for every other file located in the same path/folder:

rename-item : Cannot create a file when that file already exists.

level 1

could use copy-item or move-item to rename. Just Cp/mv sourcefile.* destfile.png

level 2

So if I wanted to copy a bunch of files in a folder named "New" and change all the extensions from "filetype._(01)" to "filetype_(01).png" would I have to type the following:

CP C:/users/me/pictures/New C:/users/me/pictures/New2.png*

Not sure if I got this right, Sorry I only know some of the utter basics so I might need this to be explained to me like I'm 5

level 1
· 5 yr. ago · edited 5 yr. ago

Damn, I thought I was still in r/commandline so I was solving this in bash. Probably not helpful here

[zomnbio@zomnbio ext]$ ls
somefile01._(01)  somefile03._(03) somefile05._(05)  somefile07._(07)  somefile09._(09) somefile02._(02)  somefile04._(04)  somefile06._(06)  somefile08._(08)  somefile10._(10)
[zomnbio@zomnbio ext]$ for file in ./*; do mv $file ${file%.*}.png; done;
[zomnbio@zomnbio ext]$ ls
   somefile01.png  somefile03.png. somefile05.png  somefile07.png  somefile09.png somefile02.png  somefile04.png  somefile06.png  somefile08.png  somefile10.png
level 1

I'm a bot, bleep, bloop. Someone has linked to this thread from another place on reddit:

 If you follow any of the above links, please respect the rules of reddit and don't vote in the other threads.(Info/ ^Contact)


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK