Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post

    folders to subfolders, simple modification

    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 Code:
    <?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);
    ?>

  • #2
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post
    *bump*

  • #3
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    Posting how the tarring works would be helpful...

  • #4
    Regular Coder
    Join Date
    Jan 2006
    Location
    Preston, Lancashire, England
    Posts
    285
    Thanks
    0
    Thanked 0 Times in 0 Posts
    try this
    PHP Code:
    <?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
    Last edited by MRMAN; 04-26-2006 at 03:36 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •