Important alert: (current site time 7/15/2013 10:25:25 AM EDT)
 

VB icon

Alphabetical File Display

Email
Submitted on: 11/17/2002 7:18:27 PM
By: Matt McCormick  
Level: Beginner
User Rating: By 1 Users
Compatibility: PHP 4.0
Views: 13774
(About the author)
 
     Simple script to display the files in a directory in alphabetical order. Example : http://www.skraped.com/users/users.php
 
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
//**************************************
// for :Alphabetical File Display
//**************************************
Copyright 2002, Skraped Networks. www.skraped.com
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
//**************************************
// Name: Alphabetical File Display
// Description:Simple script to display the files in a directory in alphabetical order.
Example : http://www.skraped.com/users/users.php
// By: Matt McCormick
//
// Inputs:No inputs.
//
// Returns:Returns a list of every file in the dir.
//
//This code is copyrighted and has// limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=811&lngWId=8//for details.//**************************************

<?php
//Copyright 2002. Skraped Networks. //
//		 Matt McCormick -=> matt@cybyte.net //
//		Edited using EditPlus 2.11//
//www.skraped.com //
if ($handle = opendir('.')) { // read the current directory. Change the "." to the directory you need.
	$filecount = "0"; //reset the number of files
while (false !== ($file = readdir($handle))) { 
if ($file != "." && $file != "..") { // remove the move up directory commands. (. and ..)
			$file = strtolower($file); // make all filenames lowercase (looks better. can be removed)
			$fileList[] = trim($file); // add the file to an array so it can be sorted easily.
			$filecount = $filecount + 1; //count the number of files
} 
}
	print 'File Count: <b>'.$filecount.'</b><br>'; //display the number of files
	sort ($fileList); // sort the file list in the array
	reset ($fileList); // go back to the top of the array
	while (list ($key, $val) = each ($fileList)) {
echo $val.'<br>'; //print the list.
	}
closedir($handle); 
}
?>


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

11/18/2002 12:19:40 AMCharles Chadwick

Instead of printing out the $filecount var, why not just say Print count($fileList)? That way you don't need $filecount at all. Also, you shouldn't need reset($fileList) because once you enter the while loop, it should start at the beginning.

Good code though.
(If this comment was disrespectful, please report it.)

 
1/2/2004 11:39:56 AMPeter van Velzen

Simple code, because it`s harder to sort files by date/time or size.
If you would ad that this code could be realy useful!!
(If this comment was disrespectful, please report it.)

 
8/11/2009 6:22:50 AMbrij

its just nice.
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.