Oihana PHP

containsFile.php

Table of Contents

Functions

containsFile()  : bool
Tells whether a directory holds a file, at any depth.

Functions

containsFile()

Tells whether a directory holds a file, at any depth.

containsFile(string $directory) : bool

Unlike hasFiles(), which only looks at the first level, this walks the whole tree: a directory holding nothing but empty sub-directories holds no file, one holding a file five levels down does.

Links count as files and are not followed: a link is something the directory holds, whatever it points at.

A directory that cannot be read is taken to hold a file, and so is one with an unreadable sub-directory. That is the safe answer for the usual question behind this call — "can this be removed as empty?" — since what cannot be seen cannot be shown to be empty.

Parameters
$directory : string

The directory to look into.

Tags
example
use function oihana\files\containsFile;

// /tmp/work/a/b/ — empty directories only
containsFile( '/tmp/work' ) ; // false

// /tmp/work/a/b/dump.sql
containsFile( '/tmp/work' ) ; // true
author

Marc Alcaraz (ekameleon)

since
1.7.0
Return values
bool —

True when a file or a link is found anywhere under it, or when part of it cannot be read; false when it holds only directories, holds nothing, or is not there.

On this page

Search results