News you won't see in controlled mainstream media.

Who's Online Now
1 members (Russ), 940 guests, and 176 robots.
Key: Admin, Global Mod, Mod
ShoutChat
October
S M T W T F S
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Left Sidebar Ad
Popular Topics(Views)
402,628 DOES GOD EXIST?
312,063 Please HELP!!!
Support Our Forum
Herbs/Nutrition
Only The Best HerbsOnly The Best Herbs!
Your best source of world-class herbal information! More...
Mercury Detox
Amalgam Illness: Diagnosis and Treatment by Dr. Andrew Cutler#1 Book We've Found!
"Silver" fillings, mercury detox, & much more. More...
Algin
AlginFor Mercury Detox
Prevent mercury reabsorption in the colon during detox. More...
Mercury Poisoning
DMSA, 25mg.Softcover & Kindle
Excellent resource for mercury detox. More...
EDTA 500mg
DMSA, 25mg.For Mercury Chelation
For calcium chelation and heart health. More...
Vaccine Safety?
Vaccines: The Risks, The Benefits, The Choices by Dr. Sherri TenpennyMust for Every Parent
The most complete vaccine info on the planet. More...
Stop Candida!
Candida ClearFinally.
Relief! More...
Saying NO To Vaccines
Saying No To Vaccines by Dr. Sherri TenpennyDr. Sherri Tenpenny
Get the info you need to protect yourself. More...
Nano-Silver
Amalgam Illness: Diagnosis and Treatment by Dr. Andrew CutlerWhat everyone's talking about!
Safe, powerful, timely! More...
World's Best Vitamin E
Vitamin E wih SeleniumThere is a difference!
A powerful brain antioxidant for use during Hg detox. More...
It's All In Your Head
It's All In Your Head by Dr. Hal HugginsThis changed my life!
This book convinced me remove my fillings. More...
World's Best Multi
Super Supplemental - Full-Spectrum Multivitamin/Mineral/Herbal SupplementThis is what we use!
The only multi where you feel the difference. More...
Understand Hair Tests
Hair Test Interpretation: Finding Hidden Toxicities by Dr. Andrew CutlerHair Tests Explained!
Discover hidden toxicities, easily. More...
GABA
GABA (gamma-aminobutyric acid)Have Racing Thoughts?
Many use GABA for anxiety and better sleep. More...
Pet Health Charts
Pet Health Charts for Dogs, Cats, Horses, and BirdsHelp Them!
Natural health for pets. More...
The Companion Bible (Hardcover)
The Companion BibleThe Bible We Use!
King James with study notes by Bullinger. More...
The Companion Bible (Softcover)
The Companion BibleThe Bible We Use!
King James with study notes by Bullinger. More...
Sweet Remedy
Sweet RemedyFood Additives
Protect your family from toxic food! More...
Previous Thread
Next Thread
Print Thread
Rate Thread
Joined: Dec 1999
Posts: 30,867
Master Elite Member
****
PHP Code
 function DirList ($Dir, $Match = null) {
		/*
		Purpose
			Used to get a list of files in a directory matching a specified regular expression.
		Parameters
			Dir (String) = The directory we're working with.
			Match (Optional String) = A regular expression used to match file names.
		Return (Array)
			Returns a list of all files in the specified directory (Dir) that match the specified expression (Match).
			The . and .. files are never included in the returned list.
			Returns false if:
				- The specified directory (Dir) does not exist.
				- The specified regular expression (Match) is invalid.
		Version History
			1.0 2012.01.01 Tested by Russ Tanner - russtanner.com
		*/

		$r = array();									   // Return buffer

		$hFile = opendir($Dir);							 // Open the specified directory
		if ($hFile === false) return false;				 // Error Trap: The specified dir is invalid, return false

		while ($FileName = readdir($hFile)) {			   // Main loop: Read all files in the specified directory

			if ($FileName != '.' && $FileName != '..') {	// Skip the files "." and ".."
				$x = preg_match($Match, $FileName);		 // Test the current file against the regexp
				if ($x === false) return false;			 // Error Trap: The specified regular expression is invalid
				if ($x == 1) $r[] = $FileName;			  // The regexp matches the file name, append it to the return buffer
			}
		}

		closedir($hFile);								   // Clean up
		return $r;										  // Return the resulting array.

	} 
 


The Captian
Today they call you "crazy". Tomorrow they call you "ahead of your time."
Global Skywatch Learn about Chemtrails - You're breathing them now!
OnlyTheBestHerbs.com World-class supplements
Mercury Talk Why you are sick.
OneUp Domains Domains, Hosting, Email
1-800-358-4278 (U.S. & Canada)
Joined: Dec 1999
Posts: 30,867
Master Elite Member
****
Improved Version:

Code

    function Dir_FileList ($Dir, $Match = null) {
        /*
        Purpose
            Used to get a list of files in a directory matching a specified regular expression.
        Parameters
            Dir (String) = The directory we're working with.
            Match (Optional String) = A regular expression used to match file names.
                Only files matching this regular expression are returned.
                If null, all files in the specified directory are returned.
                Default: null
        Return (Array)
            Returns a list of all files in the specified directory (Dir) that match the specified expression (Match).
            Directories are not returned.
            The . and .. files are never included in the returned list.
            Returns false if:
                - The specified directory (Dir) does not exist.
                - The specified regular expression (Match) is invalid.
        Examples
            $x = Files_GetList('/home');
                Returns all files in the /home directory.
            $x = Files_GetList('/home', '/.*\.txt$/');
                Returns all files in the /home directory that end in ".txt".
        Version History
            1.0 2011        Tested by Russ Tanner on PHP 5.1.6. - russtanner.com
            1.1 2012.03.28  Tested by Russ Tanner on PHP 5.3.10 - russtanner.com
                Allowed omitting Match so that ALL files are returned.
                Limited the resulting list to files only. No directories are returned.
        */

        $r = array();

        // Make sure Dir does not have a trailing slash.
        $Dir = rtrim($Dir, '/\\');

        // Open the specified directory.
        $hFile = opendir($Dir);
        // Error Trap: The specified directory (Dir) is invalid. Return false and exit.
        if ($hFile === false) return false;

        // Main loop: Read all files in the specified directory
        while ($FileName = readdir($hFile)) {

            // Skip "." and ".." and any directories.
            if ($FileName != '.' && $FileName != '..' && is_file($Dir.'/'.$FileName)) {

                // No match filter specified. Accumulate all files.
                if (is_null($Match)) $r[] = $FileName;
                // A match filter was specified. Only return files matching the regular expression (Match).
                else {
                    $x = preg_match($Match, $FileName);     // Test the current file against the regexp
                    if ($x === false) return false;         // Error Trap: The specified regular expression is invalid
                    if ($x == 1) $r[] = $FileName;          // The regexp matches the file name, append it to the return buffer
                }
            }
        }

        // Clean up and return the resulting array.
        closedir($hFile);
        return $r;

    }



Last edited by Russ; 03/29/12 02:06 PM.

The Captian
Today they call you "crazy". Tomorrow they call you "ahead of your time."
Global Skywatch Learn about Chemtrails - You're breathing them now!
OnlyTheBestHerbs.com World-class supplements
Mercury Talk Why you are sick.
OneUp Domains Domains, Hosting, Email
1-800-358-4278 (U.S. & Canada)
Joined: Dec 1999
Posts: 30,867
Master Elite Member
****
Further Improved Version

Now supports selecting between only directories or only files or both.

Code
function Dir_FileList ($Dir, $Match = null, $ObjectType = 0) {
    /*
    Purpose
        Used to get a list of files or directories in a directory matching a specified regular expression.
    Parameters
        Dir (String) = The directory we're working with.
        Match (Optional String) = A regular expression used to match file/directory names.
            Only files/directories matching this regular expression are returned.
            If null, all files/directories in the specified directory are returned.
            Default: null
        ObjectType (Optional Integer) = Determine if files or directories (or both) are returned.
            If 0, both files and directories are returned.
            If 1, only files are returned.
            If 2, only directories are returned.
            Default: 0
    Return (Array)
        Returns a list of all files/directories in the specified directory (Dir) that match the specified expression (Match).
        The . and .. files are never included in the returned list.
        Returns false if:
            - The specified directory (Dir) does not exist.
            - The specified regular expression (Match) is invalid.
    Examples
        $x = Dir_FileList('/home');
            Returns all files and directories in the /home directory.
        $x = Dir_FileList('/home', '/.*\.txt$/', 1);
            Returns all files (no directories) in the /home directory that end in ".txt".
    Version History
        1.0 2011        Tested by Russ Tanner on PHP 5.1.6. - russtanner.com
        1.1 2012.03.28  Tested by Russ Tanner on PHP 5.3.10 - russtanner.com
            Allowed omitting Match so that ALL files are returned.
            Limited the resulting list to files only. No directories are returned.
        1.2 2013.03.08  Added ObjectType parameter.
    */

    $r = array();
    
    // Make sure Dir does not have a trailing slash.
    $Dir = rtrim($Dir, '/\\');

    // Open the specified directory.
    $hFile = opendir($Dir);
    // Error Trap: The specified directory (Dir) is invalid. Return false and exit.
    if ($hFile === false) return false;

    // Main loop: Read all files in the specified directory
    while ($FileName = readdir($hFile)) {
        // Skip "." and ".." and any directories.
        if  ($FileName != '.' && $FileName != '..' && 
                (
                    ($ObjectType == 0) || 
                    ($ObjectType == 1 && is_file($Dir.'/'.$FileName)) ||
                    ($ObjectType == 2 && is_dir($Dir.'/'.$FileName))
                )
            ) {
                    
            // No match filter specified. Accumulate all files.
            if (is_null($Match)) $r[] = $FileName;
            // A match filter was specified. Only return files matching the regular expression (Match).
            else {
                $x = preg_match($Match, $FileName);     // Test the current file against the regexp
                if ($x === false) return false;         // Error Trap: The specified regular expression is invalid
                if ($x == 1) $r[] = $FileName;          // The regexp matches the file name, append it to the return buffer
            }
        }
    }

    // Clean up and return the resulting array.
    closedir($hFile);
    return $r;

}


Last edited by Russ; 03/08/13 02:49 PM.

The Captian
Today they call you "crazy". Tomorrow they call you "ahead of your time."
Global Skywatch Learn about Chemtrails - You're breathing them now!
OnlyTheBestHerbs.com World-class supplements
Mercury Talk Why you are sick.
OneUp Domains Domains, Hosting, Email
1-800-358-4278 (U.S. & Canada)
Joined: Dec 1999
Posts: 30,867
Master Elite Member
****
A Better Version with More Options

This version has added the FullPath and DirSep parameters allowing full control over the type of list that is returned

Code
function Dir_FileList ($Dir, $Match = null, $ObjectType = 0, $FullPath = false, $DirSep = null, $Suffix = '') {
    /*
    Purpose
        Used to get a list of files or directories in a directory matching a specified regular expression.
    Parameters
        Dir (String) = The directory we're working with.
        Match (Optional String) = A regular expression used to match file/directory names.
            Only files/directories matching this regular expression are returned.
            If null, all files/directories in the specified directory are returned.
            Default: null
        ObjectType (Optional Integer) = Determine if files or directories (or both) are returned.
            If 0, both files and directories are returned.
            If 1, only files are returned.
            If 2, only directories are returned.
            Default: 0
        FullPath (Optional Boolean/String) = Determines if the returned list contains only file/directory names or complete paths.
            If (boolean) false, only file/directory names are returned.
            If (boolean) true, complete paths are returned. Complete paths never contain trailing slashes.
            If a string, then this is prepended to each returned file/directory.
                This enables the easy transposition of a list of files/directories.
                When using this feature, remember to us a trailing slash to separate this string and the returned file/directory.
            Default: false
        DirSep (Optional String) = The directory separator to use.
            When returning full paths (FullPath = true), this is the directory separater used between the specified 
                directory (Dir) and each file/directory returned.
            This is also the directory separator that is expected to be present in Dir.
            This should normally be "/" on *nix systems and "\" on Windows systems, but does not have to be as Windows can
                also use "/" as a directory separator.
            This may contain zero-or-more characters.
            If null, this defaults to the current value of DIRECTORY_SEPARATOR.
            Default: null
        Suffix (Optional String) = A suffix that is appended to each element of the returned array.
            This enables easy customization of the returned list of files/directories.
            When using this feature, you will normally want to use a leading slash.
            Default: "" (zero-length string)
    Return (Array)
        Returns a list of all files/directories in the specified directory (Dir) that match the specified expression (Match).
        The . and .. files are never included in the returned list.
        Returns false if:
            - The specified directory (Dir) does not exist.
            - The specified regular expression (Match) is invalid.
    Examples
        $x = Dir_FileList('/home');
            Returns all files and directories in the /home directory.
        $x = Dir_FileList('/home', '/.*\.txt$/', 1);
            Returns all files (no directories) in the /home directory that end in ".txt".
    Version History
        1.0 2011        Tested by Russ Tanner on PHP 5.1.6. - russtanner.com
        1.1 2012.03.28  Tested by Russ Tanner on PHP 5.3.10 - russtanner.com
            Allowed omitting Match so that ALL files are returned.
            Limited the resulting list to files only. No directories are returned.
        1.2 2013.03.08  Added ObjectType parameter.
        1.3 2013.03.29  Added the FullPath, DirSep, and Suffix parameters.
    */
    $r = array();

    // Make sure Dir does not have a trailing slash.
    $Dir = rtrim($Dir, '/\\');

    // Default parameters.
    if (is_null($DirSep)) $DirSep = DIRECTORY_SEPARATOR;
    if (is_string($FullPath)) $PrefixPath = $FullPath;
    else {
        if ($FullPath) $PrefixPath = $Dir . $DirSep;
        else $PrefixPath = '';
    }

    // Open the specified directory.
    $hFile = opendir($Dir);
    // Error Trap: The specified directory (Dir) is invalid. Return false and exit.
    if ($hFile === false) return false;

    // Main loop: Read all files in the specified directory
    while ($FileName = readdir($hFile)) {
        // Skip "." and ".." and any directories.
        if  ($FileName != '.' && $FileName != '..' &&
                (
                    ($ObjectType == 0) ||
                    ($ObjectType == 1 && is_file($Dir.$DirSep.$FileName)) ||
                    ($ObjectType == 2 && is_dir($Dir.$DirSep.$FileName))
                )
            ) {

            // No match filter specified. Accumulate all files.
            if (is_null($Match)) $r[] = $PrefixPath . $FileName . $Suffix;
            // A match filter was specified. Only return files matching the regular expression (Match).
            else {
                $x = preg_match($Match, $FileName);     // Test the current file against the regexp
                if ($x === false) return false;         // Error Trap: The specified regular expression is invalid
                // The regexp matches the file name, append it to the return buffer
                if ($x == 1) $r[] = $PrefixPath . $FileName . $Suffix;
            }
        }
    }

    // Clean up and return the resulting array.
    closedir($hFile);
    return $r;

}

Last edited by Russ; 03/29/13 03:34 AM.

The Captian
Today they call you "crazy". Tomorrow they call you "ahead of your time."
Global Skywatch Learn about Chemtrails - You're breathing them now!
OnlyTheBestHerbs.com World-class supplements
Mercury Talk Why you are sick.
OneUp Domains Domains, Hosting, Email
1-800-358-4278 (U.S. & Canada)

Link Copied to Clipboard
Powered by UBB.threads™ PHP Forum Software 8.0.1