Skip to content

Instantly share code, notes, and snippets.

@kruvas
Forked from rajatkalia/copy_prog.php
Created April 16, 2013 02:11
Show Gist options
  • Save kruvas/5392812 to your computer and use it in GitHub Desktop.
Save kruvas/5392812 to your computer and use it in GitHub Desktop.
<?php
include 'linklist.class.php';
class obJect {
public $nameOfOb;
public $typeOfOb;
function __construct($nameOfOb,$typeOfOb)
{
$this->nameOfOb = $nameOfOb;
$this->typeOfOb = $typeOfOb;
}
}
$sdir = "/home/rajat/qBT_dir"; //Source Directory
$ddir = "/home/rajat/ajindertest"; // Destination Directory
$len = strlen($sdir);
$lnl = new LinkList();
$lnl->insertFirst(new obJect($sdir,"DIR"));
dirToList($sdir,$lnl);
foreach($lnl->readList() as $key => $value)
{
if($value->typeOfOb == "DIR")
{
echo "Creating Directory".refmt($value->nameOfOb,$ddir,$len)."......\n";
mkdir(refmt($value->nameOfOb,$ddir,$len),0777);
echo "Directory Successfully Created\n";
}
elseif($value->typeOfOb == "File") {
echo "Copying File ". $value->nameOfOb. " to ".refmt($value->nameOfOb,$ddir,$len)."......\n";
copy($value->nameOfOb,refmt($value->nameOfOb,$ddir,$len));
echo "File Successfully Copied \n";
}
}
function dirToList($dir,$lnl)
{
$cdir = scandir($dir);
foreach($cdir as $key => $value)
{
if(!in_array($value,array(".","..")))
{
if(is_dir($dir."/".$value))
{
$lnl->insertAfter(new obJect($dir,"DIR"), new obJect($dir."/".$value,"DIR"));
dirToList($dir."/".$value,$lnl);
}
else
{
$lnl->insertAfter(new obJect($dir,"DIR"),new obJect($dir."/".$value,"File"));
}
}
}
}
function refmt($value,$ddir,$len)
{
return substr_replace($value, $ddir , 0 , $len);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment