remove unwanted file extension!!! help!

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
jamesfui
Posts: 50
Joined: 27 Mar 2010 23:00

remove unwanted file extension!!! help!

#1 Post by jamesfui » 03 Apr 2010 05:56

hi dostips batch scripters,
is it possible to remove unwanted file extension in a text document?
for example,

ref.txt
---------------content-----------------
123.jpg
456.jpg
789.jpeg
def.bmp
ghi.bmp
jkl.pdf
abc.pdf
*.*etc
--------------content end--------------

i use the notepad replace feature & it works but for large number of
different file extensions, it is quite time consuming!! :?

can bat remove those file extension with ease???
so that the result will be as below,

ref.txt <- filter out
---------------content-----------------
123
456
789
def
ghi
jkl
abc

--------------content end--------------

thanks in advance!! :)

!k
Expert
Posts: 378
Joined: 17 Oct 2009 08:30
Location: Russia

Re: remove unwanted file extension!!! help!

#2 Post by !k » 03 Apr 2010 11:31

Code: Select all

@echo off
move ref.txt ref.bak
for /f "delims=" %%a in (ref.bak) do echo %%~na>> ref.txt

ghostmachine4
Posts: 319
Joined: 12 May 2006 01:13

Re: remove unwanted file extension!!! help!

#3 Post by ghostmachine4 » 04 Apr 2010 19:05

download sed for windows at gnuwin32.sourceforge.net/packages/sed.htm

Code: Select all

sed -i.bak "s/\..*$//" file

Post Reply