Renaming file without extra extension at the end...

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Supervisor
Posts: 2
Joined: 18 Dec 2009 19:54

Renaming file without extra extension at the end...

#1 Post by Supervisor » 18 Dec 2009 19:56

Hey all,
I am trying to make a batch file that renames a certain file type to another.
I know that if I do:
for %%a IN (*.<file extension>) DO rename "%%a" "%%a.<new file extension>"
The file will be renamed but it will have its original name with the extension along with the new extension.
For example, "Test.txt" will be renamed to "Test.txt.zip" if the command was:
for %%a IN (*.txt) DO rename "%%a" "%%a.zip"
Is there a way i could just take the name of the file and then add the extension so that "Test.zip" shows up instead of "Test.txt.zip"?

Help would be appreciated!

DosItHelp
Expert
Posts: 239
Joined: 18 Feb 2006 19:54

#2 Post by DosItHelp » 18 Dec 2009 22:31

for %%a IN (*.txt) DO rename "%%a" "%%~na.zip"
:wink:

Supervisor
Posts: 2
Joined: 18 Dec 2009 19:54

You're awesome!

#3 Post by Supervisor » 19 Dec 2009 12:02

Thank you for that!
+1 batch programming

^_^

Post Reply