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. Link to comment https://forums.phpfreaks.com/topic/23852-renama-files-under-stubdirectorys/ 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] Link to comment https://forums.phpfreaks.com/topic/23852-renama-files-under-stubdirectorys/#findComment-108358 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? Link to comment https://forums.phpfreaks.com/topic/23852-renama-files-under-stubdirectorys/#findComment-108378 Share on other sites More sharing options...
xam Posted October 14, 2006 Author Share Posted October 14, 2006 :( Link to comment https://forums.phpfreaks.com/topic/23852-renama-files-under-stubdirectorys/#findComment-108760 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.