NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page Rename A Bulk of Files

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search
5 members in live chat ~  


Closed Thread
 
LinkBack Thread Tools
Old 09-05-2008, 03:06 PM THREAD STARTER               #1 (permalink)
Senior Member
Join Date: Jul 2005
Posts: 1,492
newsiness has much to be proud ofnewsiness has much to be proud ofnewsiness has much to be proud ofnewsiness has much to be proud ofnewsiness has much to be proud ofnewsiness has much to be proud ofnewsiness has much to be proud ofnewsiness has much to be proud of
 


AIDS/HIV Save a Life

Rename A Bulk of Files


I have a list for example:

old name; new name
1234; hello
..
..
..

In a directory, the file name is 1234.jpg.
Now, I would like to change it automatically to hello.jpg.

I have a list with thousand of names that need to be renamed.

Anyone could help me or any scripts would do this.
Really appreciate that & Thanks in advance!!!
__________________
||||newsiness.com||||'""|""\__,_
| _[lol]___[lol]____ l ||__|__|)
|(@)(@)"""""""**|(@)(@)**|(@) 100% Free Online Flash games
newsiness is offline  
Old 09-05-2008, 03:22 PM   #2 (permalink)
Senior Member
 
nasaboy007's Avatar
Join Date: Jul 2005
Location: NJ
Posts: 1,219
nasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud of
 



EDIT: jk, disregard my previous post below the line. i misread your post. currently editing w/ right answer.


ok so you first want to read the file (i assume it's a text file). try this and tell me how it goes (untested, i just wrote it up on NP post real quick lol):

PHP Code:
<?php
????: NamePros.com http://www.namepros.com/programming/511112-rename-a-bulk-of-files.html
$filename 
"bigfile.txt"//path to text file
$fh fopen($filename'r');
$lines fread($fhfilesize($filename));
$lines explode("\n"$lines);

foreach(
$lines as $key=>$value) {
$indlines explode(";"$value);
$old[] = $indlines[0];
$new[] = $indlines[1];
}


if (
$handle opendir('/path/to/files')) {
   while (
false !== ($file readdir($handle))) {
       if(
array_search(substr($file0, -4), $old) !==  false) {
           
$i array_search(substr($file0, -4), $old);
            
rename($file$new[$i]); 
       }
   }

    
closedir($handle);
}






?>












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

how do you want the "hello" to be generated?

the original file names dont matter, right?

something like this would work (php). just pop it into the same directory as the images, edit the path in opendir, the var u want the new name to be, and run it.

PHP Code:
<?php
if ($handle opendir('/path/to/files')) {
$i 0;
   while (
false !== ($file readdir($handle))) {
       
$newname =  "hello" $i ".jpg";
       
rename($file$newname); 
????: NamePros.com http://www.namepros.com/showthread.php?t=511112
       
$i++;
   }

    
closedir($handle);
}
?>
Last edited by nasaboy007; 09-05-2008 at 03:37 PM.
nasaboy007 is offline  
Old 09-05-2008, 03:36 PM THREAD STARTER               #3 (permalink)
Senior Member
Join Date: Jul 2005
Posts: 1,492
newsiness has much to be proud ofnewsiness has much to be proud ofnewsiness has much to be proud ofnewsiness has much to be proud ofnewsiness has much to be proud ofnewsiness has much to be proud ofnewsiness has much to be proud ofnewsiness has much to be proud of
 


AIDS/HIV Save a Life
nasaboy007, Thanks for the help...
will test out your script and get back to you...
rep on its way.

Besides, I also found an utility that would do this...
In the FAQ page, it claims that the free utility could rename the files from a list.
http://www.bulkrenameutility.co.uk/Faq.php (Tested and it works!!!)
__________________
||||newsiness.com||||'""|""\__,_
| _[lol]___[lol]____ l ||__|__|)
|(@)(@)"""""""**|(@)(@)**|(@) 100% Free Online Flash games
Last edited by newsiness; 09-05-2008 at 03:46 PM.
newsiness is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


 
All times are GMT -7. The time now is 02:28 PM.

Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger