預定義常量:
DIRECTORY_SEPARATOR (string) :目錄分隔字元
PATH_SEPARATOR (string) :路徑分隔字元
bool chdir ( string $directory )— 改變目錄
複製代碼 代碼如下:
echo getcwd() . "\n";
chdir('public_html');
echo getcwd() . "\n";
bool chroot ( string $directory )— 改變根目錄,僅在系統支援且運行於 CLI,CGI 或嵌入 SAPI 版本時才行。
dir::dir ( string $directory )— directory 類,有三個方法可用:read,rewind(將檔案內部的位置指標重新指向一個資料流開頭) 和 close
複製代碼 代碼如下:
$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 )— 關閉目錄控制代碼
複製代碼 代碼如下:
$dir = "/etc/php5/";
if (is_dir($dir)) {
if ($dh = opendir($dir)){
$directory = readdir($dh);
closedir($dh);
}
}
string getcwd ( void )— 取得當前工作目錄
resource opendir ( string $path [, resource $context ] )— 開啟目錄控制代碼
string readdir ( resource $dir_handle )— 從目錄控制代碼中讀取條目
複製代碼 代碼如下:
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 ) —將 dir_handle 指定的目錄流重設到目錄的開頭
array scandir ( string $directory [, int $sorting_order [, resource $context ]] )— 列出指定路徑中的檔案和目錄
複製代碼 代碼如下:
$dir = '/tmp';
$files1 = scandir($dir);
$files2 = scandir($dir, 1);
print_r($files1);
print_r($files2);
http://www.bkjia.com/PHPjc/326745.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/326745.htmlTechArticle預定義常量: DIRECTORY_SEPARATOR (string) :目錄分隔字元 PATH_SEPARATOR (string) :路徑分隔字元 bool chdir ( string $directory )— 改變目錄 複製代碼 代碼如下...