php函数将目录中的文件名列表转换为php数组

时间:2014-03-09 22:42:32

标签: php xml bash plist info.plist

如何从目录中提取文件名列表并将其存储到php中的数组中?

如何从xml文档中获取值?

如何提取目录中文件的路径/名称并将其存储到数组中?

AKA:

$proj_dir = "~/directory/path/to/project_files;"; // same as output from {query}

$data_dir = "~/directory/path/to/data_files;";

$query = "{query}"; // returns path to project being accessed. current output of $proj_dir

从某个名为info.plist的xml文件中获取bundle id并将其存储到数组中的某种方法。与json_decode()

类似
$bundle_id_from_proj = function_to_pull_bundleid_out_of_the_file("bundle_id", '"{query}" . "/info.plist"');

$directories = array();

$cmd1 = # some way to get names of files in data/ directory via bash script
exec("$cmd");

$directories = # some way to pull values out of that array and store in php array

foreach ($directories as $directory) {
     // if title of a directory in data directories = bundleID of project
     if ( $directories['title'] === $bundle_id_from_proj )
     {
          $cmd2 = 'open -a Finder "$directory"';
          exec("$cmd2");
     }
     else
     {
          $cmd3 = 'Sorry! Can\'t find it';
          echo $cmd3;
     }

}

1 个答案:

答案 0 :(得分:1)

使用 glob() 获取目录中的文件/目录列表。