...

View Full Version : move, rename and copy folders



x_goose_x
04-11-2003, 12:47 AM
Is it possible to move, rename and copy folders using PHP?

Jason
04-11-2003, 12:57 AM
I am not so sure about all that, I have heard that you can copy which means you can create a new name for the file/folder...but I would search for this thread...I read it before...but then again, I don't think you can just move stuff cause that would create some massive problems.


Jason

missing-score
04-11-2003, 08:47 AM
You can copy, but I dont know if you can copy entire folders, I have never tried:

If not:



<?php

function copyFF($file,$folder,$dest)
{

$error = '';

if(!is_dir($dest))
{
if(!mkdir($dest,777))
{
$error .= 'Failed to Create Directory<br />';
}
}

for($i = 0; $i < count($file); $i++)
{

if(copy($folder.'/'.$file[$i],$dest.'/'.$file[$i]))
{
$error .= 'File '.$file[$i].' copied<br />';
}
else
{
$error .= 'Error copying '.$file[$i].'<br />';
}
}
return $error;
}

$filename = array('file1.txt','file2.txt','file3.txt');
$foldername = "folder";
$destination = "anotherfolder";

$uploads = copyFF($filename,$foldername,$destination);

echo $uploads; // Prints any errors
?>


I just quickly wrote this function, so there may be some errors, but that would have the effect of copying a dir and any files within it.

missing-score
04-11-2003, 08:48 AM
Just an afterthought, you said you wanted to move the directory completely, you might want to add rmdir() into that function ( if it even works :D )

x_goose_x
04-11-2003, 01:22 PM
I was wondering if there was a built in function to do it. I'm guesssing the isn't. Thanks for the script, but I doubt it would be very usefull if there was another directory withing the directory I want to move. I guess I could write a code that maps out the filesystem below the folder I select, creates all the folders withing it, move all the files within them to the new destination (with rename()), then go delete all the folders, one at a time from the lowest point in the branch up. At this point it's not that it would be a very hard script to write, it's that I think it would use too much of the servers ressources. Thanks everyone for the help, but I think I'm just going to forget about this function for now.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum