[php]view plain
copy
<?php
define('ds', directory_separator);
class getdirfile
} closedir( $handle );
} }else
return
$dirarray;
} //獲取檔案列表
public
function getfile( & $dir )
} closedir( $handle );
} }else
return
$filearray;
} //獲取目錄/檔案列表
public
function getdirfile( & $dir )
} }else
return
$dirfilearray;
} }
?>
例項:(相對路徑或絕對路徑)
1.獲取目錄列表
[php]view plain
copy
<?php
$dir_dir = './example';
$getdirfile = new getdirfile();
$getdir = $getdirfile->getdir( $dir_dir );
print_r($getdir);
?>
顯示:[html]view plain
copy
array
( [0] => example_one
[1] => example_two
)
2.獲取檔案列表
[php]view plain
copy
<?php
$file_one_dir = './example/example_one';
$file_two_dir = 'e:/workspace/mycode/getdirfile/example/example_two';
$getdirfile = new getdirfile();
$getfile_one = $getdirfile->getfile( $file_one_dir );
$getfile_two = $getdirfile->getfile( $file_two_dir );
print_r($getfile_one);
print_r($getfile_two);
?>
顯示:
[html]view plain
copy
array
( [0] => example.sql
[1] => example.txt
) array
( [0] => example.php
)
3.獲取目錄/檔案列表
[php]view plain
copy
<?php
$dir_dir = './example';
$getdirfile = new getdirfile();
$getdirfile = $getdirfile->getdirfile( $dir_dir );
print_r($getdirfile);
?>
顯示:[html]view plain
copy
array
( [dirlist] => array
( [0] => example_one
[1] => example_two
) [filelist] => array
( [example_one] => array
( [0] => example.sql
[1] => example.txt
) [example_two] => array
( [0] => example.php
) )
)
遍歷目錄和檔案資訊
using system using system.io namespace 檢視檔案和子目錄專案 找到個檔案.filecounter,dircounter private void exploredirectory directoryinfo dir console.writeline n ind...
linux下遍歷目錄和檔案
目錄操作相關函式 1 opendir 開啟目錄 dir opendir const char name 引數 要開啟的目錄名 返回值 指向目錄的指標 這裡的dir型別可以int dirfd dir dirp 函式轉變為描述符 fd 2 讀目錄 readdir struct dirent readdi...
C 獲取目錄和檔案列表
獲取目錄路徑下面所有檔案的內容 適用於linux和windows系統 include include include include ifdef win32 include include else include endif using namespace std 獲取指定目錄下所有檔案的檔名,不...