I have many jpg files on the server and would like to add my abc_ prefix to them, is there an easy way to do this without renaming them manually? Example: image01.jpg to abc_image01.jpg Thanks guys
Hello, this is the fastest way i can think of , as am a lil bit busy =) but could not resist a programming request enjoy =) p.s: if u like it , and always need some one to help u with programming things.. FOR FREE of course =) , PM ME <?php /* * Written By Mohie */ function getFiles($dir) { $list = array(); if($handler = opendir($dir)) { while (($sub = readdir($handler)) !== FALSE) { if ($sub != "." && $sub != ".." && $sub != "Thumb.db") { if(is_file($dir."/".$sub)) { $list[] = $sub; }elseif(is_dir($dir."/".$sub)){ $list[$sub] = $this->ReadFolderDirectory($dir."/".$sub); } } } closedir($handler); } return $list; } $directory="c:/images"; // DEFINE UR DIRECTORY HERE!!!!! $files=getFiles("$directory"); for($i=0;$i<sizeof($files);$i++) { rename("$directory/$files[$i]", "$directory/abc_$files[$i]"); } echo "DONE..."; ?>
Is there also code to remove something from a filename? Like for example all my files in one directory are called xx.avi.flv - I just want to remove the .avi part in the filename
Just modify the script by Mohie to do your job. The principles are the same for adding and for subtracting info from a file name.