1.

Solve : Removing File Extension from a Filename ...?

Answer»

I am currently using batch commands for many functions where normal windows actions are more time consuming. i.e. Copying an entire directory (15,000+ files) to a different drive, etc. I am even using them to back up specific files instead of going through the windows explorer method.

I have been using batch commands on a beginner to a somewhat intermediate level.

I have been trying to figure out a way to use batch commands to remove the ".tif" file extension from the file name; but have been failing miserably.

There are other files in the directory, but I only wish to remove the file extensions from the tiff files. (i.e. 214G6.tif). There are instances where I am only doing this for one or 2 files, but it is more often that I am doing this for 5-50 files at a time.

Is there such a method? Or am I needing to use programming to get this job done?

If I do need to use programming, is there a particular style that may be of greater interest for me to look into?
No its POSSIBLE in batch.

Code: [Select]@echo off
echo Remove Extension from What file(include extension)?
set /p file=?
set noext=%file:~0,-4%
ren %file% %noext%
echo Done
pause
Hope this Helps
,Nick(macdad-)Quote

set noext=%file:~0,-4%

Assumes that extensions have only a dot + 3 chars, no good for .jpeg therefore. Awesome ... TY ... I have been told by SOOOOOO many people that this could not be done.

Is there a way to isolate the tif files only? ... Or does this remove file extensions for ALL files?
here is other script with drag and drop feature:
Code: [Select]@echo off
SETLOCAL ENABLEDELAYEDEXPANSION

set fName=%1
if '%1' equ '' set /p fName=Enter file name:

for /f "tokens=* delims= " %%F in ('echo %fName%') do (
echo REN %%~nxF %%~nF
)

pause
if its working just change echo REN to RENThank You for your added input.

Is there a way to drag & drop multiple files for the task to be performed at one time?

or ...

for the batch command to automatically seek out ALL .tif file extensions, then rename them for me.
you just drag your file over the script.bat file and it renames it automatically

Quote
Is there a way to isolate the tif files only? ... Or does this remove file extensions for ALL files?
and by the isolate files you can use
Code: [Select]DIR /b C:\path\to\files\*.tifQuote from: Dias de verano on March 14, 2009, 12:56:25 PM
Assumes that extensions have only a dot + 3 chars, no good for .jpeg therefore.

thats true..but he's using it on a 3 char extension, and:

Quote from: eagle on March 14, 2009, 01:44:05 PM
Awesome ... TY ... I have been told by SOOOOOO many people that this could not be done.

If he needed it to do more than just dot + 3 char extensions, i would of re-wrote the code.Much appreciation goes out to those helping with this.

Well, I got the first recommendation to WORK. Unfortunately, having to enter the entire file name is not really time effective.

The 2nd recommendation did not work with dragging the file and dropping onto the ".bat" file

I did get the 2nd recommendation to work ONLY if I run the batch file, then I am able to drag & drop the file to be changed. Click on the cmd.exe window; Then Hit enter.

I removed the pause, and inserted a call command to loop it.

After I hit enter to remove the .tif, it loops back for the next file to be dragged & dropped.

Here is what I have at this point ...
Code: [Select]@echo off
SETLOCAL ENABLEDELAYEDEXPANSION

set fName=%1
if '%1' equ '' set /p fName=Enter file name:

for /f "tokens=* delims= " %%F in ('echo %fName%') do (
REN %%~nxF %%~nF
)

call RemoveFileExtension.bat

Is there a way to automate things more?

ideally, I would like to click on the .bat file, then it automatically finds the tiff files in the directory where the bat file is, changes the file names, and I am done. OR ... Do I have to KEEP feeding the files one at a time?

I must apologize for my lack of understanding here ... it has been more than 20+ years since I did this stuff, or even other forms of programming. Before finding this website, I have been at my wits end ... LOL
Quote from: eagle on March 14, 2009, 04:52:53 PM
ideally, I would like to click on the .bat file, then it automatically finds the tiff files in the directory where the bat file is, changes the file names, and I am done.

Code: [Select]for /f "delims==" %%F in ('dir /b *.tif') do ren "%%~nxF" "%%~nF"
TY TY TY TY ... There's Mundane work, then there is working smart ... Kudos to ALL to have contributed and most importantly were quite patient with me.
Anytime Fileviewpro is simplest way to CONVERT or view all types file without any problem so don't wasting your time, i think it will be great move to use this.

The Topic is over 3 years old...

SPAM link removed.


Discussion

No Comment Found