...

View Full Version : Move files from one directory to another



stfc_boy
07-08-2010, 12:18 PM
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

ahayzen
07-08-2010, 12:29 PM
Hi stfc_boy

That doesn't look like HTML or CSS. Did you post this in the wrong section?
if so please move to the relevant section.

Andy

santhoshj400
07-08-2010, 12:35 PM
hi check this If the destination file already exists, it will be overwritten.

$file = 'example.txt';
$newfile = 'example.txt.bak';

if (!copy($file, $newfile)) {
echo "failed to copy $file...\n";
}

Hope this helps

Thanks and Regards
santhosh



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum