Mr Chris Posted July 14, 2010 Share Posted July 14, 2010 Hello All, Hoping someone can kindly help. I'm looking to move any files from one directory (parsers) to another (complete). Now i've tried two ways <? /* Set the path details */ $path = '/home/*******/parsers/test/parse/'; //Directory which I read from $complete = '/home/*******/parsers/test/complete/'; //Directory which I wish to place into $dir = opendir($path); while (false !== ($file = readdir($dir))) { rename("$path/$file", "$complete/$file"); } ?> But this way errors: home/cfpdigi/*******/test/parse//.,/home/*******/parsers/test/complete//.) [function.rename]: Device or resource busy and this way... <? /* Set the path details */ $path = '/home/*******/parsers/test/parse/'; //Directory which I read from $complete = '/home/*******/parsers/test/complete/'; //Directory which I wish to place into $dir = opendir($path); rename("$path/$file", "$complete/$file"); ?> Moves file to 'complete' but then completely deletes the 'parse' folder, when I want the 'parse' folder to remain in place, but just have it's contents moved to 'complete'? Anyone help? Thanks Link to comment https://forums.phpfreaks.com/topic/207745-ve-files-from-one-directory-to-another/ Share on other sites More sharing options...
AbraCadaver Posted July 14, 2010 Share Posted July 14, 2010 I would use glob() instead of opendir(), but to fix your issue: /* Set the path details */ $path = '/home/*******/parsers/test/parse'; //Directory which I read from $complete = '/home/*******/parsers/test/complete'; //Directory which I wish to place into $dir = opendir($path); while (false !== ($file = readdir($dir))) { if(!is_dir("$path/$file")) { rename("$path/$file", "$complete/$file"); } } Currently it is trying to rename dirs also . (current) and .. (parent) at a minimum. Also, you don't need a slash at the end of the path var because you're adding it in between the path and file anyway. Link to comment https://forums.phpfreaks.com/topic/207745-ve-files-from-one-directory-to-another/#findComment-1086010 Share on other sites More sharing options...
Mr Chris Posted July 14, 2010 Author Share Posted July 14, 2010 Thanks! Link to comment https://forums.phpfreaks.com/topic/207745-ve-files-from-one-directory-to-another/#findComment-1086027 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.