Jump to content

ve files from one directory to another


Mr Chris

Recommended Posts

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.