2009-12-01 36 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); 
     } 
    } 
    } 
?> 

我认为这可能是你在找什么。

相关问题