Knowledgebase
Script to rename files
Posted by Niranjana, 04-03-2010, 05:47 AM | I have 100s of pdf files named as follows
1 - New file.pdf
2 - Another_file.pdf
01 - Next pdf file.pdf
5 - One more pdf file.pdf
I want to rename them as:
New file.pdf
Another_file.pdf
Next pdf file.pdf
One more pdf file.pdf
Please suggest a script to do this.
|
Posted by klikli, 04-03-2010, 07:10 AM | With Linux ( sh, etc. ) or PHP script?
|
Posted by Niranjana, 04-04-2010, 03:53 AM | I need a bash/perl scripts
|
Posted by nonamez, 04-04-2010, 05:27 AM | linux or windows ?
|
Posted by ianeeshps, 04-05-2010, 12:47 AM | If you are using linux. thats simple.
1. mv all pdf to a directorey
2. mkdir /test
3. mv *.pdf to /test
4. then change direcotry cd /test
5.
#! /bin/bash
for i in `ls`
do
s=`echo $i |cut -d- -f2`
mv $i $s
done
you can use the following script to change the names if you specified the patter correctly like - in between then otherwise tell i will modify it for you.
|
Posted by Niranjana, 04-05-2010, 01:28 AM | Yeah, I'm using ubuntu:
Please note there is spaces for file names, like "New file.pdf", "One more pdf file.pdf", so for loop will count them as separate entries. Any suggestions?
|
Posted by UNIXy, 04-05-2010, 01:41 AM | Try this one:
Regards
Joe / UNIXY
|
Posted by Niranjana, 04-05-2010, 10:27 AM | Yeah, It is working fine. Thank you Joe :-)
|
|
Add to Favourites
Print this Article |
Also Read