Listing all directories, sub directories and files starting from the root
well . and  .. are not directories, thats are navigationpoints of directories, . means go inside a root directory, .. means go one folder back, 

you might noticed this already in includes like include ../../../foo/bar.php 

also instead of scandir and readdir php has classes for this purpose DirectoryIterator or FileSystemIterator 

And if you wish to create reusable methods, dont do output there, instead return an array of folders/files something like

$directories = scanDirectories($rootDirectory); //create output array
foreach($directories as $directory){
    echo $directory.'&lt;br/&gt;';  
} 


this allowes you to modify the output without editing the sourcecode, you could also wrap the output within a function e.g. viewDirectories and reuse it on different places.

here is a small Example 

    ini_set('html_errors', 'On');

function scanDirectory($path) {
    $path = realpath($path);

     return  new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST);

}

foreach(scanDirectory('./') as $name=&gt; $object){

    echo $name.'&lt;br/&gt;';
}


About your question:

$root.$dir_list[$var].$name //this is your directory name


but youre checking if this name is . and ..

$dir_list[$var]


so its never becomes true