xam Posted October 13, 2006 Share Posted October 13, 2006 hello,I've over 500 files with same names (with same specialtag) under many dirs + subdirectorysexample: d:/ftp/directory1/subdirectory/specialtag_filename1.gifd:/ftp/directory2/subdirectory/subdirectory2/specialtag_filename1.psdd:/ftp/directory2/subdirectory2/subdirectory3/specialtag_filename2.jpghow do I change the specialtag front of each file?example:d:/ftp/directory2/subdirectory/subdirectory2/[b]specialtag[/b]_filename1.psdtod:/ftp/directory2/subdirectory/subdirectory2/[b]xam[/b]_filename1.psdord:/ftp/directory2/subdirectory2/subdirectory3/[b]specialtag[/b]_filename2.jpgtod:/ftp/directory2/subdirectory2/subdirectory3/[b]xam[/b]_filename2.jpgis this possible with php?regards,xam. Quote Link to comment Share on other sites More sharing options...
xsist10 Posted October 13, 2006 Share Posted October 13, 2006 This is very rough and untested. I hacked this together from some of my old code.The parts of the filename you want to change will be put in the subdirectory array.[code]<?php$extensions = array(".psd");$ignore = array(".", "..");$subdirectory = array( "directory2/subdirectory/subdirectory2" => array("from" => "specialtag_", "to" => "xam_"));public function parseList($dir="") { global $extensions, $ignore, $subdirectory; // Add a / if required if($dir && substr($dir, -1) != "/") $dir .= "/"; if ($directory_handle = opendir($dir)) { while(($file_handle = readdir($directory_handle)) !== false) { if (in_array($file_handle, $ignore)) { } else if (is_dir($dir . $file_handle)) { parseList($dir . $file_handle); } else { foreach (extensions as $extension) { if (strpos($file_handle, $extension) !== false && subdirectory[$dir]) { $old_name = $dir . $file_handle; $new_name = $dir . str_replace(subdirectory[$dir]["from"], subdirectory[$dir]["to"], $file_handle); copy($old_name, $new_name); unlink($old_name); } } reset(extensions); } } }}?>[/code] Quote Link to comment Share on other sites More sharing options...
xam Posted October 13, 2006 Author Share Posted October 13, 2006 thank u but there are over 300 subdirectorys and 500 files with different extentions.. i dont want write these names myself.. :) its possible to find subdirs + files = changa names only? Quote Link to comment Share on other sites More sharing options...
xam Posted October 14, 2006 Author Share Posted October 14, 2006 :( Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.