Solved

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

Posted on 2008-06-15
3
413 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 18

Expert Comment

by:Matthew Kelly
ID: 21790489
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
ID: 21790491
0
 
LVL 49

Expert Comment

by:Roonaan
ID: 21791424
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Echo values after a query in php 5 52
CSV export single column not inserting comma's in file 11 67
SSL unsecure page mystery 17 47
sitemap.xml 3 32
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

752 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