1.

Solve : Remove extension with .bat file?

Answer»

I would like to know to make a .bat file that will remove an extension (eg: .tif) from a file (or many files) that COULD be located anywhere on my computer.

For example:
C:\MyBackups\090809.tif
C:\TEST\090809.tif
D:\Backups\090809.tif

to
C:\MyBackups\090809
C:\TEST\090809
D:\Backups\090809

I would also like this .bat to run each time Windows boots

Is this possible ?

If so, please post exactly what I need to put in my .bat

Thank you !Here's the code. Save it into your startup folder.
@echo off
For /f "tokens=1,2 delims=." %%a in ('dir /b /s *.tif') do ren %%a.%%b %%aQuote from: Helpmeh on September 08, 2009, 06:25:35 PM

Here's the code. Save it into your startup folder.
@echo off
For /f "tokens=1,2 delims=." %%a in ('dir /b /s *.tif') do ren %%a.%%b %%a
the PROBLEM with this is IF (ever) the file names contain more than one dot, the rename will fail. Its better to just get RID of the .gif at the back by substituting or sub-stringing. Thanks for the help Helpmeh, but it did not work.

I created a .txt file in my root drive (C:\). Copied & pasted the code you posted exactly Code: [Select]@echo off
For /f "tokens=1,2 delims=." %%a in ('dir /b /s *.tif') do ren %%a.%%b %%a I then closed the txt file & named it TEST.bat. I kept the .bat in my root drive & created a shortcut directly from it to my Startup folder.
Then I rebooted my computer & saw the .bat run (which btw, took quite awhile - more than 1 min).
I checked a test .tif I MADE to see if the extension had been deleted & it had not. The test .tif file is located in a sub-folder under my root drive & should of been easy to find.
There is only one dot - right before the tif

1. Can this code be adapted for any extension ? For example to remove a .doc extension would it be:Code: [Select]@echo off
For /f "tokens=1,2 delims=." %%a in ('dir /b /s *.doc') do ren %%a.%%b %%a
2. Would it run faster if it knew the directory (folder) the file(s) were in ?

3. Is there a way to make it run invisibly ? (without the DOS window)

Please let me know how to make this work - its been bugging me for awhile now

TIAIs it just me or is there a new line after the ren command. That may be my iPod, but it could cause the problem if that is the case. Try ADDING PAUSE at the end of my script (on a new line) and see what it says when you run it. Thanks for the reply

I'm not sure what you mean by a new line - I don't see one...

I added PAUSE to a new line below the code you gave me. I'm not sure what happened but the DOS screen did not appear. It also did not remove the .tif extension either, so it could of just not run at all.

Can anyone help with my points I made earlier ?To your points, in any order you want: Yes, yes, yes.

Try adding SETLOCAL ENABLEDELAYEDEXPANSION right between @echo off and the for command.


Discussion

No Comment Found