0

How to check if in directory "713" there is any directory (not files)? 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;
Fury
  • 4,643
  • 5
  • 50
  • 80

1 Answers1

0
    ...
    ...

    $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;
Fury
  • 4,643
  • 5
  • 50
  • 80