There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
DOS/Other
Tag Cloud
access acer audio blue screen boot bsod crash dell drive driver drivers error ethernet excel freeze gaming google hard drive hdmi internet internet explorer internet explorer pop ups keyboard laptop malware memory missing monitor motherboard network not working problem ram router security server software svchost.exe trojan ubuntu ubuntu 11.10 uninstall video virus vista windows windows 7 windows 7 64 bit windows xp wireless
Search
Search for:
Tech Support Guy Forums > Operating Systems > DOS/Other >
Batch renaming file extensions

Reply  
Thread Tools
Fractalogic's Avatar
Computer Specs
Member with 168 posts.
 
Join Date: Jul 2010
Location: Sweden
Experience: Advanced
07-Aug-2011, 07:47 AM #1
Question Batch renaming file extensions
Hey all!

I have a bunch of files in a folder and I need to set the correct file extensions for these files.

They actually use more than one extension. The file names consist of a prefix, a infix and a suffix. So it's like two file extensions one after another. The infix is the actual extension for the file type, while the last extension or the "suffix" is an appended temporary extension.

The file name scheme looks like this.
Code:
 0001 IMG - Description [year].jpg.tmp
The appended ones needed to be removed in order for the right software to be associated to the file type. I used the REN command in CMD to remove it.

Code:
ren *.jpg.tmp *.jpg
After doing this the file names changed to something like this:

0001 IMG - Description [year].jpg.jpg

So although the files were now associated to the right software they had a double file extension (jpg). So I used the REN command once again.

Code:
ren *.jpg.jpg *.
After doing this most files were now set and ready, with only one file extension as I wanted. But some of them now don't have a file extension at all.

My question is, how do I add the file extension to those files who don't have any extension? They all have different names, so have do you "select" all those who don't have a file extension and set a new extension for these?
Fractalogic's Avatar
Computer Specs
Member with 168 posts.
 
Join Date: Jul 2010
Location: Sweden
Experience: Advanced
07-Aug-2011, 08:01 AM #2
The files that still need an extension have a file name beginning with a number, like this.

Code:
0004
0005
0052
0059
0063
0064
0065
0071
0086
......
How can I target these files for file rename command?

They don't have a file extension anymore. And the year values at the end of the file name are different for most of the files. So they don't have any text string in common so to speak. I mean it doesn't say like "2008" for each and every one of them. Because that would be easier. You could just use wildcard characters to specify only files with the "2008" in the name. But you also need to consider that this might affect the other filed which already have a file name extension, should they contain "2008" in their name as well. But I guess you can overcome this by temporarily moving those files to a different folder.

Any ideas? Thoughts?

Can't I just type in something like this:

Code:
ren 0005*; 0052*; 0059 *.jpg
That doesn't look right, I know. But to use a command similar to this would be great.

Last edited by Fractalogic; 07-Aug-2011 at 08:20 AM..
Squashman's Avatar
Trusted Advisor with 18,731 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: Bocks of Rox
07-Aug-2011, 11:45 PM #3
Well as far as your first post goes, this is what I would have done.

Batch file
Code:
@echo off
For /f "tokens=* delims=" %%I in ('dir /a-d /b *.tmp') do rename "%%~I" "%%~nI"
Output
Code:
C:\Users\Squashman\batch\rename>dir /a-d /b *.tmp
image1.jpg.tmp
imgag2.jpg.tmp

C:\Users\Squashman\batch\rename>extension.bat

C:\Users\Squashman\batch\rename>dir /a-d /b *.jpg
image1.jpg
imgag2.jpg

C:\Users\Squashman\batch\rename>
Now with your 2nd post you are saying there is no extension at all on the file names? If that is the case the file extension modifier should be null or not defined. As long as there are no periods at all in the file names you could do something like this. There can be no periods. The command modifiers really don't know what the file extension is. It just works backwards with the file name until it finds a period. So if I have a file named Image1.Squashman, the batch file will tell me that Squashman is the file extension.

Batch
Code:
@echo off
For /f "tokens=* delims=" %%I in ('dir /a-d /b *') do IF "%%~xI"=="" rename "%%~I" "%%~I.jpg"
Output
Code:
C:\Users\Squashman\batch\rename>dir /b
extension.bat
image1.jpg
Image3
image4
imgag2.jpg
No_extension.bat

C:\Users\Squashman\batch\rename>No_extension.bat

C:\Users\Squashman\batch\rename>dir /b
extension.bat
image1.jpg
Image3.jpg
image4.jpg
imgag2.jpg
No_extension.bat

C:\Users\Squashman\batch\rename>

Last edited by Squashman; 08-Aug-2011 at 12:18 AM..
Reply

Tags
batch, cmd, file, ren, rename

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.
Thread Tools



Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 11:19 PM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.