Need a script to delete files with a number in the neame

Hi experts!
I need this fast so I don't have the time to hash through it, and besides, I know somebody out there has already solved it  :)

I need a script that will look at the file names in a folder and delete the ones containing a number.
I have:
c:\folder\file
c:\folder\file1
c:\folder\file2
c:\folder\file3
etc
I need to delete all the  "file1", "file2", and "file3"..., but leave "file" intact
batch or VBscript will be the easiest to implement..
Thanks!
LVL 5
drmarstonAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

oBdACommented:
Try the script below, just adjust the folder name at the beginning; it will delete anything with a number in the name found in this folder (it won't process subfolders at the moment).
The script is currently in test mode, it will only display the "del" commands it would otherwise run, but not actually delete anything, so that you can test it.
To run it for real, remove the capitalized "ECHO" in front of the "del" command.
@echo off
setlocal
set Root=C:\Folder
for /f "delims=" %%a in ('dir /b /a:-d "%Root%\*.*" ^| findstr /r ".*[0-9][0-9]*.*"') do (
  Deleting %%a ...
  ECHO del "%Root%\%%a"
)

Open in new window

0
sirbountyCommented:

ParentFolder="C:\folder\"
 
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objFolder : Set objFolder = objFSO.GetFolder(ParentFolder)
 
For Each File in objFolder.Files
  strFile = Replace(file.name, "." & objFSO.GetExtensionName(file),"")
  If IsNumeric(Right(strFile,1)) Then
    wscript.echo "Deleting " & file.name
    objFSO.DeleteFile (file)
  End If
Next

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
drmarstonAuthor Commented:
Sirbounty: works perfectly, Thanks!
oBdA: I got an error with yours, but appreciate the speedy response!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Scripting Languages

From novice to tech pro — start learning today.