PHPDirectory function detail_php tutorial

Source: Internet
Author: User
PHPDirectory function details. Predefined constant: DIRECTORY_SEPARATOR (string): directory separator PATH_SEPARATOR (string): path separator boolchdir (string $ directory)-Change the directory copy code as follows:

DIRECTORY_SEPARATOR (string): directory separator

PATH_SEPARATOR (string): path separator


Bool chdir (string $ directory)-Change directory

The code is as follows:

Echo getcwd (). "\ n ";
Chdir ('public _ html ');
Echo getcwd (). "\ n ";


Bool chroot (string $ directory)-change the root directory only when the system supports and runs on CLI, CGI, or SAPI version.

Dir: dir (string $ directory)-directory class. There are three methods available: read, rewind (pointing the position pointer inside the file to the beginning of a data stream again) and close

The code is 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 directory handle

The code is as follows:


$ Dir = "/etc/php5 /";

If (is_dir ($ dir )){
If ($ dh = opendir ($ dir )){
$ Directory = readdir ($ dh );
Closedir ($ dh );
}
}


String getcwd (void)-get the current working directory

Resource opendir (string $ path [, resource $ context])-open the directory handle

String readdir (resource $ dir_handle)-read entries from the directory handle

The code is 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)-reset the directory stream specified by dir_handle to the beginning of the Directory

Array scandir (string $ directory [, int $ sorting_order [, resource $ context])-List files and directories in a specified path

The code is as follows:


$ Dir = '/tmp ';
$ Files1 = scandir ($ dir );
$ Files2 = scandir ($ dir, 1 );
Print_r ($ files1 );
Print_r ($ files2 );

Export DIRECTORY_SEPARATOR (string): directory separator PATH_SEPARATOR (string): path separator bool chdir (string $ directory)-Change the directory code 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.