ylkien Posted December 7, 2006 Share Posted December 7, 2006 Hi all,I created this simple code to list everything in a folder. Your feedback is utmost appreciated![code]function Get_Directory_Listing( $dir ){ if( is_dir( $dir ) ) { //This is added so that it can enter & list the sub-directories nicely if( (substr( $dir, -1) !== "/") || (substr( $dir, -1) !== "\\") ) $dir .= "\\"; //This is the main function, whereby it enters the folders and list their contents if( $dir_open = opendir( $dir ) ) { while( ( $file = readdir( $dir_open ) ) !== false ) { if( $file == "." || $file == ".." ) continue; if( filetype( $dir . $file ) == "dir") { echo "<BR><BR><b>Directory found : $dir$file </b>"; //if( substr( Get_Directory_Listing( $dir . $file ); } echo "<BR>Filename : $file, filetype : " . filetype( $dir . $file ); } } closedir( $dir_open ); } else { //This is incase the user forgets to put the semicolon after the drive letter $dir .= ":"; echo "<BR>Drive to be listed : $dir"; Get_Directory_Listing( $dir ); }}[/code] Link to comment https://forums.phpfreaks.com/topic/29758-listing-files-in-directories-and-its-sub-directories/ Share on other sites More sharing options...
ted_chou12 Posted December 7, 2006 Share Posted December 7, 2006 is there a way to show/hide specific files and general files?eg. say i want to hide "secrete.txt"and I only want to show "dir" extension files.THanks Link to comment https://forums.phpfreaks.com/topic/29758-listing-files-in-directories-and-its-sub-directories/#findComment-136943 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.