Why i list my directory file got dots

<?php
include 'config.php';

if(isset($_POST['btn-upload']))
{    

$log_directory = '/XAMPP/htdocs/mydoc';

$results_array = array();

if (is_dir($log_directory))
{
        if ($handle = opendir($log_directory))
        {
                //Notice the parentheses I added:
                while(($file = readdir($handle)) !== FALSE)
                {
                        $results_array[] = $file;
                }
                closedir($handle);
        }
}

//Output findings
foreach($results_array as $value)
{
    echo $value . '<br />';
}
}
?>

Open in new window


This is my output, got dots before my output .. anyone know how to throw the dots
Anyone know how to throw the dots .. because i only want to display my file
Scott Yong Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dr. KlahnPrincipal Software EngineerCommented:
A simple way to remove them from your output is to evaluate the length of the filename inside the "foreach", and echo only if the length is three or more.
1
Ryan ChongCommented:
or make a condition to exclude them in the loop:

                while(($file = readdir($handle)) !== FALSE)
                {
                      if (!($file == ".") && !($file == "..")) {
                        $results_array[] = $file;
                      }
                }

Open in new window

1
Nitin SontakkeDeveloperCommented:
Couple of suggestions:

1/ If you are interested only in your files, which i presume have .csv extension, you are better of getting files of .csv extension only.

2/ If date is part of your filename, I strongly suggest that you use yyyyMMdd format for naming files. Highly helpful while sorting and identifying the file in list of files. Or at least think of making day part two digits 02 instead of just 2. That itself will improve the view. Same for month, if not already done.
1
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

gr8gonzoConsultantCommented:
Do NOT just check the length of the filename! You might eventually have a legitimate file that is 1 or 2 characters long!

The . and .. entries are legitimate parts of the filesystem and are present in EVERY folder because they are not really physical entries but rather special entries that represent the current directory and the parent directory.

The . represents the CURRENT directory.
The .. represents the PARENT directory.

So if you listed the contents of "/XAMPP/htdocs/..", you would actually see the contents of "/XAMPP" because .. goes up one level to the immediate parent.

If you listed the contents of "/XAMPP/htdocs/../..", you would see the contents of "/" because the two ".." entries would first go from htdocs to XAMPP and then from XAMPP to the root / folder.

The single dot can be useful in some scenarios, but they're a little hard to explain WHY you would use them since the scenarios are typically less common. But let's say you listed the contents of "/XAMPP/htdocs/." - you would see the contents of "/XAMPP/htdocs". Or if you listed "/XAMPP/./htdocs" you would also see the contents of "/XAMPP/htdocs".

In my loops, I usually just use the "continue" statement to skip those entries:

while(($file = readdir($handle)) !== FALSE)
{
  if (($file == ".") || ($file == "..")) { continue; }
  ... rest of your loop logic here...
}

Open in new window

1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gr8gonzoConsultantCommented:
Also, if you want a quick shortcut for getting all your CSV files, just use glob():
<?php
include 'config.php';

if(isset($_POST['btn-upload']))
{    
  $log_directory = '/XAMPP/htdocs/mydoc';
  $results_array = array();

  if (is_dir($log_directory))
  {
    $results_array = glob($log_directory . "/*.csv");
  }

  //Output findings
  foreach($results_array as $value)
  {
    echo $value . '<br />';
  }
}
?>

Open in new window

That code will make $results_array contain ONLY the CSV files inside that folder and will automatically skip over the . and .. entries.
1
Scott Yong Author Commented:
Good Explain man .. thank you
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.