Page 1 of 1

Renaming file without extra extension at the end...

Posted: 18 Dec 2009 19:56
by Supervisor
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!

Posted: 18 Dec 2009 22:31
by DosItHelp
for %%a IN (*.txt) DO rename "%%a" "%%~na.zip"
:wink:

You're awesome!

Posted: 19 Dec 2009 12:02
by Supervisor
Thank you for that!
+1 batch programming

^_^