简体   繁体   English

检查路径以查看是否有任何目录php

[英]check path to see if there is any directory php

How to check if in directory "713" there is any directory (not files)? 如何检查目录“ 713”中是否有目录(不是文件)? it has to be smart enough to ignore file existance 它必须足够聪明以忽略文件的存在

    ...
    ...

    $workRecordFullPath = "/var/www/websites/AM_dev/app/webroot/files/submissions/57601/4189/713/";

    // check if folder "713" exists     
    if (file_exists($workRecordFullPath)) {
    // check if into 713 there is any directory
        if (!is_dir($workRecordFullPath)) {
            return true;
        }
    } 
    return false;
    ...
    ...

    $workRecordFullPath = "/var/www/websites/AM_dev/app/webroot/files/submissions/57601/4189/713/";
    // get all directories in "713"
    $submissionWorkRecordFullPath = glob($workRecordFullPath . '*' , GLOB_ONLYDIR);

    // check if folder "713" exists     
    if (file_exists($workRecordFullPath)) {
    // check if into 713 there is any directory
        if (!empty($submissionWorkRecordFullPath)) {
            return true;
        }
    } 
    return false;

The other solution will be counting slashes "/" 另一种解决方案是计算斜杠“ /”

  $oldQc = 12; // The deep number of folders to wrok_record_id

  $objects = new RecursiveIteratorIterator(
              new RecursiveDirectoryIterator($workRecordFullPath),
              RecursiveIteratorIterator::SELF_FIRST
  );

  foreach($objects as $name => $object){

        // Name of all flies and directories
        $countSlashes = substr_count($name,'/');

        if ($countSlashes>$oldQc) {
            return false;
        }
  }

  return true;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM