Computing.Net > Forums > Programming > Removing Numbers from Filename

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Removing Numbers from Filename

Reply to Message Icon

Name: AJR3
Date: October 12, 2009 at 20:51:37 Pacific
OS: Windows Vista
CPU/Ram: Core2Quad Q6700 4GB RAM
Subcategory: Batch
Comment:

Hi, I am wondering how I might go about removing all numbers from all the files in a directory (and how I might exclude certain files from this rename which are named in a exclude.txt in the same directory).

Thank You,
AJR3



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: October 13, 2009 at 15:29:30 Pacific
Reply:

This will get you started. You'll get errors if, for instance, you have:

file1
file2

It will rename the first to file and error on the second.

It is smart enough not to rename 123.doc to .doc, which you probably don't want.

==================================

@echo off & setLocal EnableDELAYedExpansion

for /f "tokens=* delims= " %%a in ('dir/b') do (
find /i "%%a" < exclude.txt > nul

if errorlevel 1 (
  set str=%%~Na
  call :sub1
if "!str!" neq "" (
  echo ren "%%a" "!str!%%~Xa"
)
)
)
goto :eof

:sub1
  for /L %%i in (0 1 9) do (
    if "!str!" neq "" (
      set str=!str:%%i=!
    )
  )
goto :eof


=====================================
Helping others achieve escape felicity

M2


0
Reply to Message Icon

Related Posts

See More






Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: Removing Numbers from Filename

Batch remove %20 from filenames www.computing.net/answers/programming/batch-remove-20-from-filenames/13957.html

Remove quotes from user input string www.computing.net/answers/programming/remove-quotes-from-user-input-string/19410.html

extracting number from a string SQL www.computing.net/answers/programming/extracting-number-from-a-string-sql/3902.html