PDA

View Full Version : folders to subfolders, simple modification



thesavior
04-25-2006, 03:20 PM
Okay, so I have this code. This code takes a direcrory and adds it to a .tar. I want it to go through and add subfolders underneath the directory as well. Any idea what to change? Ill post up tar.php if you need me to.


<?php
include('tar.php');

$new_tar = new tar();

$directory = 'the_directory';

$new_tar->addDirectory($directory);
$d = opendir($directory);
while (false !== ($entry = readdir($d))) {
if($entry != '.' && $entry != '..' && !is_dir($entry))
$new_tar->addFile($directory.'/'.$entry);
}
closedir($d);
$new_tar->toTar('myTarFile.tar', false);
?>

thesavior
04-26-2006, 02:31 PM
*bump*

GJay
04-26-2006, 02:41 PM
Posting how the tarring works would be helpful...

MRMAN
04-26-2006, 03:00 PM
try this


<?php

include('tar.php');

$new_tar = new tar();
godirectory('the_directory');
$new_tar->toTar('myTarFile.tar', false);

function godirectory($directory)
{
$d = opendir($directory);
$new_tar->addDirectory($directory);
while (($entity = readdir($d)) !== false)
{
if($entity != '.' && $entity != '..')
{
if(is_dir($directory.'/'.$entity))
{
godirectory($directory.'/'.$entity);
}
else
{
$new_tar->addFile($directory.'/'.$entity);
}
}
}
closedir($d);
}

?>


please note that i havn't been able to test this as i am not by my usual pc.
But what it should to is call the godirectory function with the start directory. When in there if it finds a folder is will jump into it and search that and will continue till not folders ot files are there to search