Suchy Posted April 28, 2007 Share Posted April 28, 2007 I have a simple script to rename files. <?php $path = 'fotki_upload'; $dir_handle = opendir($path); while ($file = readdir($dir_handle)) rename($file, strtoupper($file)); closedir($dir_handle); ?> But I am getting these errors. Warning: rename(wixa.jpg,WIXA.JPG) [function.rename]: No such file or directory in /home/suchygn/public_html/media/fotka/rename.php on line 9 Warning: rename(.,.) [function.rename]: Device or resource busy in /home/suchygn/public_html/media/fotka/rename.php on line 9 Warning: rename(1.jpg,1.JPG) [function.rename]: No such file or directory in /home/suchygn/public_html/media/fotka/rename.php on line 9 Warning: rename(3.jpg,3.JPG) [function.rename]: No such file or directory in /home/suchygn/public_html/media/fotka/rename.php on line 9 Warning: rename(index.html,INDEX.HTML) [function.rename]: No such file or directory in /home/suchygn/public_html/media/fotka/rename.php on line 9 Warning: rename(..,..) [function.rename]: Device or resource busy in /home/suchygn/public_html/media/fotka/rename.php on line 9 What seems to be the problem, the direcotry where the files are i chomed to 777. Quote Link to comment Share on other sites More sharing options...
neel_basu Posted April 28, 2007 Share Posted April 28, 2007 The problem is not in rename(). The file/directory you are trying to access is not there its in some other location. Try chdir($path); just after opendir() and after your job is done add chdir('../'); or something like that at the end. Quote Link to comment Share on other sites More sharing options...
neel_basu Posted April 28, 2007 Share Posted April 28, 2007 Or try rename($path./.$file, strtoupper($file)); Quote Link to comment Share on other sites More sharing options...
ignace Posted April 28, 2007 Share Posted April 28, 2007 // The mistake you make, is very common // you forgot to include the path, because the file 1.jpg does not exist // in your current directory, but it exists in your upload_folder/1.jpg while ($file = readdir($dir_handle)) { if ($file <> "." && $file <> "..") { $full = $path . DIRECTORY_SEPERATOR . $file; rename($full, strtoupper($full)); } } Quote Link to comment Share on other sites More sharing options...
ignace Posted April 28, 2007 Share Posted April 28, 2007 if it says that DIRECTORY_SEPERATOR does not exist, then add the following code just above that snippet: (normally it is implemented into php) define('DIRECTORY_SEPERATOR', (substr(PHP_OS, 0, 3) == 'WIN') ? "\\" : "/")); Quote Link to comment Share on other sites More sharing options...
Suchy Posted April 28, 2007 Author Share Posted April 28, 2007 Thanks 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.