[英]Find directory path (recursive) matching directory name
I have the following directory structure: 我有以下目录结构:
/mnt/disk/documents
/mnt/disk/data/files/
/mnt/disk/data/morefiles/
The mount point disk/
is variable. 安装点disk/
是可变的。 I need to get all files from data/
and it's sub directories. 我需要从data/
及其子目录中获取所有文件。 I know how to list files with glob
but in this case I need first find the directory data
and than all files recursively. 我知道如何用glob
列出文件,但是在这种情况下,我需要先找到目录data
然后递归地查找所有文件。
How can I do that, not knowing the full path from the beginning? 从一开始就不知道完整路径,我该怎么做?
One way. 单程。
realpath ( string $path );
realpath() expands all symbolic links and resolves references to '/./', '/../' and extra '/' characters in the input path and returns the canonicalized absolute pathname. realpath()扩展所有符号链接,并解析对输入路径中“ /./”、“/../”和多余的“ /”字符的引用,并返回规范化的绝对路径名。
Example: 例:
PHP: PHP:
<?php
echo realpath('/windows/system32');
echo realpath('C:\Program Files\\');
?>
Result: 结果:
C:\WINDOWS\System32
C:\Program Files
Simple way. 简单的方法。 Any questions, just ask that I will try to answer. 有任何问题,请问我会尝试回答。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.