• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 838
  • Last Modified:

Mass File RENAMER - To Rename thousands of files

Can anyone recommend a way to rename lots of files, for example:

"Strip off the first 4 characters of the filename and Rename the file to that"
OR
"Strip off all characters up to the first "dash" then Rename the file to that".

Platform doesn't matter ... they are all small files .. I can move them anywhere to get the job done (Windows or MSDOS Command Line or Mac or Linux)

Thanks
0
bleggee
Asked:
bleggee
  • 9
  • 3
  • 3
  • +4
5 Solutions
 
strungCommented:
0
 
Paul TomasiCommented:
Strip off first 4 characters

@echo off
setlocal enabledelayedexpansion

for %%a in (*.*) do (
  if "%%~nxa" neq "%~nx0" (
    set fn=%%a
    ren "%%" "!fn~4!"
  )
)

Open in new window

0
 
Paul TomasiCommented:
Strip off upto the first dash (including the dash)

@echo off
for /f "tokens=1-2* delims=-" %%a in ('dir /a-d /b *.*') do (
  if "%%a-%%b" neq "%~nx0" ren "%%a-%%b" "%%b"
)

Open in new window

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Paul TomasiCommented:
Oops! Apologies. I meant this:

Strip off first 4 characters.

@echo off
setlocal enabledelayedexpansion

for %%a in (*.*) do (
  if "%%~nxa" neq "%~nx0" (
    set fn=%%a
    ren "%%a" "!fn:~4!"
  )
)

Open in new window

0
 
Paul TomasiCommented:
Oops! Error in my second comment too. I meant:

@echo off

for %%a in (*.*) do (
  if "%%a" neq "%~nx0" (
    for /f "tokens=1-2* delims=-" %%b in ('echo %%a') do ren "%%a" "%%c"
  )
)

Open in new window

0
 
Brian PringleSystems Analyst II, SCM, ERPCommented:
Try Renamewiz.  I have used this many times, especially when you want to rename a batch of pictures or something like that with arcane names.

http://www.renamewiz.com/
0
 
bleggeeAuthor Commented:
Thanks ! Both of those solutions (Paul & Strung) will work great!
Paul - What would I change to strip off "Up to the Dash PLUS the space after that" ... so that:
"012 - filename.txt"
becomes
"filename.txt"
without leaving a leading blank space character?
0
 
Paul TomasiCommented:
To hide false errors (where seom files may not have a dash) I've amended line 5.

Strip off upto the first dash (including the dash).

@echo off

for %%a in (*.*) do (
  if "%%a" neq "%~nx0" (
    for /f "tokens=1-2* delims=-" %%b in ('echo %%a') do ren "%%a" "%%c" 2>nul
  )
)

Open in new window

0
 
bleggeeAuthor Commented:
(thx also btringle ... you snuck in a good solution also when I wasn't looking ;-)
0
 
Paul TomasiCommented:
bleggee


so that "012 - filename.txt" becomes "filename.txt"
The '6' in line 7 will remove remove the first 6 characters from the filename:

@echo off
setlocal enabledelayedexpansion

for %%a in (*.*) do (
  if "%%~nxa" neq "%~nx0" (
    set fn=%%a
    ren "%%a" "!fn:~6!"
  )
)

Open in new window

0
 
Paul TomasiCommented:
Another way is like this:

@echo off
setlocal enabledelayedexpansion

for %%a in (*.*) do if not "%%a"=="%~nx0" set "fn=%%a" & call :ProcFn %%a & ren "%%a" "!fn!"

:ProcFn
  for %%c in (" " "-" 0 1 2 3 4 5 6 7 8 9 0) do if "%fn:~0,1%"=="%%~c" set "fn=%fn:~1%" & goto ProcFn
goto :eof

Open in new window

But if you have a filename like this: '002 - 9 steps to paradise.mp3' then you'll end up with just 'steps to paradise.mp3' (you lose the '9 ') as it gobbles up any leading numbers, spaces and '-' signs. Otherwise it's good to go.
0
 
Lionel MMSmall Business IT ConsultantCommented:
I use this--small and easy to use and you can apply any rule and even multiple changes to file names
http://www.den4b.com/?x=products&product=renamer
0
 
flubbsterCommented:
This is the only one I have ever used. It is super easy, incredibly versatile, and even allows modifications of file created and modified time stamps. The besat part about it is that you can see the actual results before committing to the change. It allows a huge number of modifications based on exactly what you are trying to accomplish.

http://www.bulkrenameutility.co.uk/Main_Intro.php
0
 
Paul TomasiCommented:
lionelmm
flubbster

The problem with all such 'Renamer' utilities is that they need to be downloaded onto the computer. Some systems do not allow this.

Also, it often means learning a bunch of new syntax rules.

DOS is well-equiped to do what the asker wants to do. DOS can accomplish anything a third party utility can if you know what buttons to push.

Personally, for me, it's easier to throw something together in DOS and not have to rely on third party programs - but then, I'm a die-hard DOS guru.

Having said that, that's not to say I won't look at those programs though...

Bottom line: It's great to see diversity!
0
 
Jim-RCommented:
+1 for BulkRenamer.  I use this program flubster suggested.  As confusing as it looks like to start with, it is pretty easy to figure out with a little help from the tutorial link.
0
 
flubbsterCommented:
Paultomasi.....

There is no syntax you need to learn. You simply select what you want to change from and to...
0
 
Paul TomasiCommented:
flubbster...

So, are you talking about a GUI app here or a command line app?
0
 
flubbsterCommented:
It's a gui.

You know... you could have just clicked on the link and looked at the screen shots.

http://www.bulkrenameutility.co.uk/Screenshots.php
0
 
bleggeeAuthor Commented:
Thanks all !
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

  • 9
  • 3
  • 3
  • +4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now