Solved

How to scan folders & sub folders to print sorted numbered list?

Posted on 2008-06-15
3
374 Views
Last Modified: 2013-12-13
Hi

I need php code to scan folders & sub flders and then print sorted, numbered list. It will also disply number of files found in that folder.

Plz avoid using functions wherevere possible to do this. Simple php code will be preffered.

0
Comment
Question by:theredcode
  • 2
3 Comments
 
LVL 18

Expert Comment

by:Matthew Kelly
Comment Utility
In order to read sub folders you will need to use a function. See the code below for a basis of just outputting the files.

Change the path at the very bottom of the code snippet to the path you want to look at. PHP must have access to that path for the script to execute. Try it out.
function read_my_dir($dir)

{

	global $tfile,$tdir;$i=0;$j=0;$myfiles;

	$myfiles[][] = array();

	if (is_dir($dir))

	{

		if ($dh = opendir($dir))

		{

			while (($file=readdir($dh)) !== false)

			{

				if (!is_dir($dir."\\".$file))

				{

					$tfile[$i]=$file;

					$i++;

					echo $dir."\\".$file." - <b>File</b><br>";

				}

				else

				{

					if (($file != ".") && ($file != ".."))

					{

						$tdir[$j]=$file;

						echo $dir."\\".$file." - <b>Directory</b><br>";

						//$sep = "\\";

						read_my_dir($dir."\\".$file);

						$j++;

					}

				}

			}

			closedir($dh);

		}

	}

}
 

read_my_dir("C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\experts-exchange");

Open in new window

0
 
LVL 18

Accepted Solution

by:
Matthew Kelly earned 500 total points
Comment Utility
0
 
LVL 49

Expert Comment

by:Roonaan
Comment Utility
Hi,

Can you show me your desired output format in a quick example?

On what field do you need your output to be sorted? Number of subdirectories? Number of files, or just alphanumerical?

Kind regards

-r-
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now