Reiterative Copy() in a Directory Alternative
| From: | Wei, Alice J. | Date: | Tue, 10 Jun 2008 14:42:41 +0000 |
| Subject: | Reiterative Copy() in a Directory Alternative | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-275185@lists.php.net to get a copy of this message | ||
Hi,
I have a scenario here where I wanted to read through a directory and copy all the files into
another directory out on the server somewhere.
It appears that I cannot do reiterative copying from the files to another folder, according to the
error I keep seeing:
PHP Warning: copy(a2.txt): failed to open stream: No such file or directory in
/home/ajwei//Desktop/file_copy.php on line 18
Error! Couldn't copy a2.txt to /home/ajwei/Documents/test1/a2.txt
Is it possible that there is an alternative for this? I have no problems with reading through the
directory using readdir(),
<?
if ($handle = opendir('/home/ajwei/Desktop/test/')) {
echo "Directory handle: $handle\n";
echo "Files:\n";
mkdir("/home/ajweiDocuments/test1", 0755);
while (false !== ($file = readdir($handle))) {
echo "$file\n";
$result= copy($file, '/home/ajwei/Documents/test1/$file');
if ($result) {
echo "$file has been copied to /home/ajwei/Documents/test1/$file\n\n";
}
else {
echo "Error! Couldn't copy $file to /home/ajwei/Documents/test1/$file\n";
}
}
}
closedir($handle);
Is there an alternative to what I am meant to do if the copy() cannot be functioned the way I
anticipated?
I welcome any suggestion.
Alice
======================================================
Alice Wei
MIS 2009
School of Library and Information Science
Indiana University Bloomington
ajwei@indiana.edu