exec 函数不起作用

发布于 2024-08-23 04:10:58 字数 609 浏览 2 评论 0原文

我从 http://kevin.vanzonneveld.net/techblog/article/convert_anything_to_tree_structs_in_php/ 找到了这段代码,但我无法让它工作。我正在 WIndow 环境中工作,我使用的路径是 /sellable,其中可销售是工作文件夹内的文件夹:

if(exec("find /etc/php5", $files)){
    // the $files array now holds the path as it's values,
    // but we also want the paths as keys:
    $key_files = array_combine(array_values($files), array_values($files));

    // show the array
    print_r($key_files);
}

任何人都可以帮助我吗?

I found this code from http://kevin.vanzonneveld.net/techblog/article/convert_anything_to_tree_structures_in_php/, but I couldn't get it work. I am working on WIndow environment and the path I use is /sellable where the sellable is the folder inside the working folder :

if(exec("find /etc/php5", $files)){
    // the $files array now holds the path as it's values,
    // but we also want the paths as keys:
    $key_files = array_combine(array_values($files), array_values($files));

    // show the array
    print_r($key_files);
}

Can anyone help me ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

〗斷ホ乔殘χμё〖 2024-08-30 04:10:58

在 Windows 计算机上,您几乎不会获得 find 命令,也不会获得 /etc/php5 目录。使用 PHP 的内置 glob 或 < Strike>DirectoryIterator RecursiveDirectoryIterator (谢谢帕斯卡:)。 Glob 本身无法迭代子文件夹,但链接页面上的用户贡献注释中有简单的 globr 实现。迭代器可以本机执行此操作。

You are hardly going to get the find command, nor a /etc/php5 directory on a windows machine. Use PHP's built-in glob or the DirectoryIterator RecursiveDirectoryIterator (Thanks Pascal :) instead. Glob can't iterate through sub-folders natively, but there are simple globr implementations in the User Contributed Notes on the linked page. The iterator can do this natively.

落叶缤纷 2024-08-30 04:10:58

find 是一个 Linux 命令(外部 Linux 程序)。

这意味着它不会出现在 Windows 上...

并且 /etc/php5 确实看起来像目录的 UNIX 路径;并且看起来不像 Windows 目录的路径。

所以,这里有两个问题:

  • 你必须找到一个等价的... find
    • 也许使用 cygwin 之类的东西?
  • 您必须调整路径,使其适合您的系统

但我想说仅 PHP 的解决方案可能会更好:有一些函数和类允许您搜索文件并迭代文件系统 - 并且它可以在 Linux 和 Linux 上运行Windows,不依赖于任何外部程序。

例如,要迭代目录,您可能需要查看 RecursiveDirectoryIterator 类 - 也许还有 DirectoryIterator

find is a Linux command (an external Linux program).

Which means it will not be present on windows...

And /etc/php5 really looks like an UNIX path to a directory ; and doesn't look like a path to a Windows directory.

So, two problems here :

  • You have to find an equivalent of... find.
    • Maybe using something like cygwin ?
  • You have to adapt the path, so it fits your system

But I'd say that a PHP-only solution would probably be better : there are functions and classes that will allow you to search files and iterate over the filesystem -- and it would work on both Linux and Windows, not depending on any external program.

For instance, to iterate over a directory, you might want to take a look to the RecursiveDirectoryIterator class -- and maybe also DirectoryIterator.

廻憶裏菂餘溫 2024-08-30 04:10:58

我还没有尝试过,但“dir /s /bc:\somedir”可能可以作为 Windows 上“find”的快速替代品。更好(且更便携)的解决方案是使用 RecursiveDirectoryIterator 或 php 的 opendir/readdir 函数来递归列出目录中的所有文件。

请参阅此处的示例代码,例如:
http://php.net/manual/en/function.readdir.php

i haven't tried it, but "dir /s /b c:\somedir" might work as a quick replacement for "find" on windows. a better (and more portable) solution would be to use the RecursiveDirectoryIterator or php's opendir/readdir functions to recursively list all files in a directory.

see example code here for example:
http://php.net/manual/en/function.readdir.php

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文