如何生成一个正则表达式模式,从这些行中的任何一行返回文件名?(我将一次搜索一行).
drwxrwxrwx 4 apache apache 4096 Oct 14 09:40 .
drwxrwxrwx 11 apache apache 4096 Oct 13 11:33 ..
-rwxrwxrwx 1 apache apache 16507 Oct 17 10:16 .bash_history
-rwxrwxrwx 1 apache apache 33 Sep 1 09:36 .bash_logout
-rwxrwxrwx 1 apache apache 176 Sep 1 09:36 .bash_profile
-rwxrwxrwx 1 apache apache 124 Sep 1 09:36 .bashrc
-rwxrwxrwx 1 apache apache 515 Sep 1 09:36 .emacs
-rw------- 1 christoffer christoffer 11993 Sep 18 10:00 .mysql_history
drwxrwxrwx 3 apache apache 4096 Sep 1 09:48 .subversion
-rwxrwxrwx 1 christoffer christoffer 9204 Oct 14 09:40 .viminfo
drwxrwxrwx 14 apache apache 4096 Oct 12 07:39 www
Run Code Online (Sandbox Code Playgroud)
搜索是使用PHP完成的,但我想这并没有真正有所作为.:)
编辑:文件列表由SSH连接检索,这就是为什么我不使用内置的PHP函数.我需要这个完整的列表来查看文件是否实际上是一个目录.
试试吧ls -a1F.这将列出所有条目(-a),每行一个(-1),以及有关附加到名称(-F)的文件类型的其他信息.
然后,您可能会为您的目录获得以下内容:
./
../
.bash_history
.bash_logout
.bash_profile
.bashrc
.emacs
.mysql_history
.subversion/
.viminfo
www/
Run Code Online (Sandbox Code Playgroud)
目录/末尾有一个斜杠.
主要问题是......为什么?使用readdir和stat替代.
<?php
$directory = './';
$dh = opendir($directory);
while (($file = readdir($dh)) !== false)
{
$stat = stat($directory.$file);
echo '<b>'.$directory.$file.':</b><br/>';
var_dump($stat);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5537 次 |
| 最近记录: |