2009-12-01 58 views

回答

0

scandir()將帶來所有文件名到數組中。

陣列SCANDIR(字符串$目錄 [摘要$ sorting_order = 0,資源$背景]])

<?php 

    $dir = '/tmp'; 
    $files1 = scandir($dir); 
    $files2 = scandir($dir, 1); 

    print_r($files1); 
    print_r($files2); 

?> 
+0

謝謝喬納森! – John 2009-12-01 18:25:54

+0

本例來自PHP網站,請提供適當的信用! – Michael 2009-12-01 18:28:12

+0

謝謝喬納森。我相信這是我需要的。 – John 2009-12-01 18:30:23

0

我假設你有興趣在PHP這樣做。您將要使用的關鍵功能是scandir函數和file_get_contents函數。

所以,你是源將是這個樣子:

<?php 
    $my_dir_path = "/path/to/my/dir"; 
    $files = scandir($my_dir_path); 
    $files_contents_to_array = new Array(); // will contain a mapping of file name => file contents 
    if($files && count($files) > 0) { 
    for($files as $file) { 
     if($file /* some pattern check, verify it is indeed the file you need */) { 
     $files_contents_to_array[$file] = file_get_contents($file); 
     } 
    } 
    } 
?> 

我認爲這可能是你在找什麼。

相關問題