Renaming Multiple Files (Tutorial)

Status
Not open for further replies.

sms_solver

In the zone
A) Renaming multiple files (the WinXP way)

1) Go to the directory in which there are files that you want to rename.
2) Click on View>Thumbnails from the menu in the explorer. This step is not necessary but useful while dealing with graphics file.
3) Select only those files that you want to rename. For that hold down the [Ctrl] key, click on icons of only those files that you want to rename.
4) Position your mouse pointer above any of the selected file. NOw rt-click your mouse, select Rename. Give any name you desired.

5) Now the selected files will have same new name but with different numbered prefix as shown in the figure.

*img260.echo.cx/img260/6770/renwinxp27oj.th.png

Renaming multiple files and extensions with DOS
1) Under Win9x, Me; Click on Start>Run... Type command to be at DOS prompt. Use cmd under Win2000 or above.
2) Go to the desired directory using "change directory" command.
eg: C:\>cd \Phtotos\MyPhotos.
3) Now (for example) if you wish to change all file's extension from .jpg to something like .tmp. Type the following command. ren *.jpg *.tmp
4) Work complete!! Repeat step 3 with some changes to get the original back.

SOME more examples of "ren"

Example1: ren *in*.* *sn*.* . This will replace the string "in" with "sn" in all those files which have "in" string of current directory.

Example2: ren S*.* p*.*. This will replace all filename starting with letter "S" with "P" regardless of the extension of current directory.

B) Renaming multiple files with IrfanView batch renaming

1) Open IrfanView (this tutorial works best with ver 3.95 or above)
2) Open any one file from the directory having many files that you want to rename.
3) Press the key T to open IrfanView Thumbnail viewer.
4) Select only those files that you want to rename. For that hold down the [Ctrl] key, click on thumbnails of only those files that you want to rename. Press

F2 key. This will open Batch Conversion dialog box.
5) Click on Batch rename radio option to select it. At name pattern textbox give the new name following with hash(#) sign. Keep Output Directory textbox blank, if not the renamed files will be either copied or moved to the defined Output Directory.

*img243.echo.cx/img243/5980/renirfan11yf.png

(NOTE: If you want e.g. 3 digits in the new renamed name, you have to write "#" thrice in the pattern!
Example: pattern image_### with start index 1 & increment 1 will produce file names image_001, image_002, etc..)

6) Click on Start button to start the renaming process.

SOME more examples to be used at name pattern textbox

Example1: pattern My$N_## with start index 1 and increment 1 will add prefix My to all renamed files along with 2 digit numbering like My$N_01, My$N_02, My$N_03, etc...

Example2: pattern ##_$N_Impo with start index 1 and increment 2 will produce file names like 01_$N_Impo, 03_$N_Impo, 05_$N_Impo, etc....

Example3: pattern $N### with start index 100, increment 10 and replace text (1)=2004 with=2005 will first replace the string 2004 with 2005 in old filenames and then add numbering like $N100, $N110, $N120, $N130, etc....

$N ==> Represents old file name.

==============================
Some USEFUL RENAMING SOFTWARES
==============================
1) Flexible Renamer v6 or above. Flexible Renamer is a file/folder renaming utility, which can use Wildcard or Regular-Expression and Tag-information (MP3, EXIF).

LINK: *hp.vector.co.jp/authors/VA014830/FlexRena (This is old link, if link is not working, search the google with "Flexible Renamer" or "FlexRena".
DEVELOPED IN: Delphi
TYPE: FREEWARE
SIZE: < 600 KB

2) Flash Renamer v4.6 or above. Shareware software for easy renaming of multiple files & directories.

LINK: *www.rlvision.com
DEVELOPED IN: Visual Basic
TYPE: SHAREWARE
SIZE: < 700 KB

---------------------TUTORIAL PREPARED BY SMS_SOLVER:08-MAY-2005--------------------
 

pallavnawani

Broken In
1. Renaming multiple files in Linux, the command line way

rename <pattern> <replace_pattern> <filename(s)>
For example, given the files foo1, ..., foo9, foo10, ..., foo278, the
commands

rename foo foo0 foo?
rename foo foo0 foo??

will turn them into foo001, ..., foo009, foo010, ..., foo278.

And
rename .htm .html *.htm
will fix the extension of your html files.

2. Renumbering Images
Often, images you download from websites may have rubbish characters in their name, and different style of names. Example:
porshe.jpg, red_proshe.bmp, 01-porshe.gif etc.
Following bash script will allow you to turns all of these into something like:
porshe001.jpg, porshe002.jpg, porshe003.jpg and so on.
Not only this, it will also convert them to required image format!. So use it only if you're working on images.

Usage: seqname.bash <prefix> <suffix> <filename(s)>
Example:
seqname.bash porshe .jpg *.bmp
Will convert all bmp files in the directory to jpg format, and will rename them as well (Seqname.bash being the name of the bash script).

So, here is the script:

Code:
#!/bin/bash

#Check for the number of arguments
if [ $# -lt 3 ]; then
   echo "Usage: seqname.bash <prefix> <suffix> file1 [file2 ...]"
   echo "Prefix, Suffix, and filename1 are mandatory parameters."
   exit
fi

#create the temp directory
tmpdir=/tmp/$RANDOM
mkdir $tmpdir
if [ $? != 0 ]; then
   echo "Unable to create temporary directory, exiting."
   exit
fi

#Take out the first name, we use it as a prefix
count=0
prefix1=$1
prefix2="$tmpdir/$1_"
suffix=$2
suffixlen=${#suffix}
negsuffix=$((-$suffixlen))
shift 2

for files in "$@"
do

#Get suitable number of zeroes into the filename
   csize=${#count}
   cdiff=$((4-$csize))
   prefix3=$prefix2
   while [ $cdiff -gt 0 ]; do
      prefix3="$prefix3"0
      cdiff=$(($cdiff-1))     
   done
   newname=${prefix3}${count}${suffix}
   nsuffix=${files:$negsuffix:$suffixlen}

#if the original file has a different suffix than the
#one we specified, try to use convert to convert between
#formats, else simply use mv.

   if [ $nsuffix != $suffix ]; then

      echo "convert ${files} $newname"
      convert ${files} $newname
      if [ $? != 0 ]; then
         echo "Unable to use convert, trying simple move"
   	 echo "mv ${files} $newname"
   	 mv ${files} $newname
      fi

      else
         echo "mv ${files} $newname"
   	 mv ${files} $newname
   fi

   count=$(($count+1))
done

#Now copy the renamed files from the temporary directory to
#our working directory, and delete the temp directory
echo "mv $tmpdir/* ."
mv $tmpdir/* .
echo "rmdir $tmpdir"
rmdir $tmpdir

3. Fixing the case of the filenames and other things.
If you download mp3s/pdfs etc from the web, they will come with names like:
eBooks_-_Manga_-_How_to_Draw_General_Anime_Faces_-_Julie_Dillon.pdf
Psychology_-_Unstoppable_Confidence.pdf

Fixing it by hand is a lot of work. I have a bash script (Actually two versions) which will fix it automatically. It does the following:
Convert all chars to lowercase
Replace all spaces by _ (underscore)
replace all - by _ (underscore)
removes all '
removes all [
etc. This may be or may not be what you want. So running my script on the names:
fixname.bash *.pdf
Gives:
ebooks_manga_how_to_draw_general_anime_faces_julie_dillon.pdf
psychology_unstoppable_confidence.pdf

And here is the script:

Code:
#!/bin/bash

for files in "$@"
do
   newname1=$(echo ${files}  | tr -s "[:blank:]-" _ )
   newname2=$(echo $newname1  | tr "[:upper:]" "[:lower:]")
   newname3=$(echo $newname2  | tr -d "\',\`;()[]" )

   if [ "$files" != "$newname3" ]; then
      echo "mv ${files} ${newname3}"
      mv "${files}" "${newname3}"
   fi
done

I also have a recursive version of this script, which will recursively descend into the subdirectories and do the operation in those files (it will also rename the directories if necessary) as well.


Code:
#!/bin/bash

for files in "$@"
do
   newname1=$(echo ${files}  | tr -s "[:blank:]-" _ )
   newname2=$(echo $newname1  | tr "[:upper:]" "[:lower:]")
   newname3=$(echo $newname2  | tr -d "\',\`;()[]" )

   if [ "$files" != "$newname3" ]; then
      echo "mv ${files} ${newname3}"
      mv "${files}" "${newname3}"
   fi

   if [ -d $newname3 ]; then
      echo "cd $newname3"
      cd $newname3
      echo "sh $0 *"
      sh $0 *
      cd ..
   fi
done

Bye,
Pallav
 

pallavnawani

Broken In
Ok, I searched a bit and found GUI renaming utilities for Linux:


*freshmeat.net/projects/gprename/
*www.krename.net/

Enjoy!
Pallav
 

moxy123

Right off the assembly line
Hai guys why dont you give a try to 'Namewiz'. Its an excellent software for renaming. you can download the trial version from www.softbytelabs.com. The current version is 4.10. But I find version 3.15 the best and comfortable to work. Just give it a try and let me know.
 

ashisharya

In the zone
moxy123 says:
Hai guys why dont you give a try to 'Namewiz'. Its an excellent software for renaming. you can download the trial version from www.softbytelabs.com. The current version is 4.10. But I find version 3.15 the best and comfortable to work. Just give it a try and let me know.

correct..but its feel good when u do it manually
 

gary4gar

GaurishSharma.com
good work
for rename instead of right click u can also press f2.

if u khow this spread it.if don't khow it n joy it
 

JGuru

Wise Old Owl
I have written my own program in Java. It renames files in a fly. It can work in Windows,
Linux, Solaris, AIX, UNIX etc., Using the software you can do more customization than
the one XP offers!!
 

silverPolygons

Right off the assembly line
JGuru said:
I have written my own program in Java. It renames files in a fly. It can work in Windows,
Linux, Solaris, AIX, UNIX etc., Using the software you can do more customization than
the one XP offers!!
Oooh yeah? where's that program wizzy?? i thought you would share a link!!
or you just came here to brag about your little Java program??

pallavnawani said:
Ok, I searched a bit and found GUI renaming utilities for Linux:


*freshmeat.net/projects/gprename/
*www.krename.net/

Enjoy!
Pallav
Hey thanks for the links dude... I was badly looking for them but google just didn't tell.. this is one of the few times google let me down..
Well, your links saved the day.. esp coz i don't know how to write bash files or whateva you call them.. will soon learn that.. and yep.. your tute was helpful too.. :)
cheers
 
Last edited:
Status
Not open for further replies.
Top Bottom