A detailed _php tutorial on PHP Directory functions

Source: Internet
Author: User
Pre-defined constants:

Directory_separator (String): Directory delimiter

Path_separator (String): Path delimiter


BOOL ChDir (String $directory)-Change Directory

Copy the Code code as follows:

Echo GETCWD (). "\ n";
ChDir (' public_html ');
Echo GETCWD (). "\ n";

BOOL Chroot (String $directory)-Changes the root directory only if the system supports it and is running in cli,cgi or embedded SAPI version.

Dir::d ir (string $directory)-directory class, there are three methods available: Read,rewind (the position pointer inside the file is pointed back to the beginning of a data stream) and close

Copy the Code code as follows:
$d = Dir ("e:/work/html");
foreach ($d as $k = = $v) {
echo $k. ' $v. '
';
}
while (false!== ($entry = $d->read ())) {
echo $entry. "
";
}
$d->close ();

void Closedir (Resource $dir _handle)-Close the directory handle

Copy the Code code as follows:
$dir = "/etc/php5/";

if (Is_dir ($dir)) {
if ($dh = Opendir ($dir)) {
$directory = Readdir ($DH);
Closedir ($DH);
}
}

String getcwd (void)-Gets the current working directory

Resource Opendir (String $path [, Resource $context])-Open Directory handle

String Readdir (Resource $dir _handle)-Reads an entry from the directory handle

Copy the Code code as follows:
if ($handle = Opendir ('/path/to/files ')) {
echo "Directory handle: $handle \ n";
echo "files:\n";
while (false!== ($file = Readdir ($handle))) {
echo "$file \ n";
}
Closedir ($handle);
}

void Rewinddir (Resource $dir _handle)-Resets the Dir_handle specified directory stream to the beginning of the directory

Array Scandir (string $directory [, int $sorting _order [, Resource $context]]-Lists the files and directories in the specified path

Copy the Code code as follows:
$dir = '/tmp ';
$files 1 = scandir ($dir);
$files 2 = Scandir ($dir, 1);
Print_r ($files 1);
Print_r ($files 2);

http://www.bkjia.com/PHPjc/326745.html www.bkjia.com true http://www.bkjia.com/PHPjc/326745.html techarticle Predefined constants: Directory_separator (String): Directory delimiter Path_separator (string): Path delimiter bool ChDir (string $directory)-Change Directory Replication code The code is as follows ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.