Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP检查动态命名文件夹是否存在_Php_File - Fatal编程技术网

PHP检查动态命名文件夹是否存在

PHP检查动态命名文件夹是否存在,php,file,Php,File,我在使用php检查是否存在同名文件夹时遇到问题。我知道我可以用 file_exists() 检查文件夹或文件是否存在,但问题是我正在检查的文件夹的名称可能会有所不同 我有一些文件夹,其中名称的第一部分是固定的,而“\u1”之后的部分可能会有所不同。例如: 文件夹0, 每个文件夹都将以“folder_uu”开头,但在“u”之后可以是任何内容 无论如何,我可以检查是否存在具有此属性的文件夹 提前谢谢。 SR您可以循环浏览父文件夹中的所有文件/文件夹: $folder = '/path-to-you

我在使用php检查是否存在同名文件夹时遇到问题。我知道我可以用

file_exists()
检查文件夹或文件是否存在,但问题是我正在检查的文件夹的名称可能会有所不同

我有一些文件夹,其中名称的第一部分是固定的,而“\u1”之后的部分可能会有所不同。例如: 文件夹0, 每个文件夹都将以“folder_uu”开头,但在“u”之后可以是任何内容

无论如何,我可以检查是否存在具有此属性的文件夹

提前谢谢。
SR

您可以循环浏览父文件夹中的所有文件/文件夹:

$folder = '/path-to-your-folder-having-subfolders';
$handle = opendir($folder) or die('Could not open folder.'); 
while (false !== ($file = readdir($handle))) { 
    if (preg_match("|^folder_(.*)$|", $file, $match)) {
        $curr_foldername = $match[0];
        // If you come here you know that such a folder exists and the full name is in the above variable
    }
}

循环浏览父文件夹中的所有文件/文件夹:

$folder = '/path-to-your-folder-having-subfolders';
$handle = opendir($folder) or die('Could not open folder.'); 
while (false !== ($file = readdir($handle))) { 
    if (preg_match("|^folder_(.*)$|", $file, $match)) {
        $curr_foldername = $match[0];
        // If you come here you know that such a folder exists and the full name is in the above variable
    }
}
e、 g

e、 g


你可以这样检查它=>“file_exists('dir/folder.'.$i)”或is_dir('dir/folder.'.$i)要使用那种方法我需要知道$i是什么,但我不知道,它可以是任何东西,它是动态创建的。你可以这样检查它=>“file_exists('dir/folder.'.$i)”或is_dir('dir/folder.'.$i)要使用那种方法我需要知道$i是什么,但我不知道,它可以是任何东西,它是动态创建的。
print_r(find_wildcard_dirs("/tmp/santos_*'));