【问题标题】:php function pull list of file names in directory into a php arrayphp函数将目录中的文件名列表拉入php数组
【发布时间】:2014-03-09 22:42:32
【问题描述】:

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

如何从 xml 文档中获取值?

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

又名:

$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 文件中获取捆绑包 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;
     }

}

【问题讨论】:

  • 请一次一个问题,除非它们非常相关。在这种情况下,解析 XML 和获取文件列表是不相关的。
  • 对不起!有很多事情要弄清楚。不要试图压倒任何人。

标签: php xml bash plist info.plist


【解决方案1】:

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

【讨论】:

  • 我尝试使用 glob(),它给了我迄今为止找到的 2 个输出。 1. 输出:数组(); // 一个空数组 2. 输出:不存在这样的文件或目录 // 然后是路径
  • @AlexCory 你用什么作为函数的参数?
猜你喜欢
  • 2014-06-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-08-27
  • 2011-01-12
  • 1970-01-01
  • 2012-06-09
相关资源
最近更新 更多