CDE
This commit is contained in:
parent
518da4a923
commit
764da6cbbb
6144 changed files with 83610 additions and 11 deletions
16
Task/Empty-directory/PHP/empty-directory.php
Normal file
16
Task/Empty-directory/PHP/empty-directory.php
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
$dir = 'path_here';
|
||||
|
||||
if(is_dir($dir)){
|
||||
//scandir grabs the contents of a directory and array_diff is being used to filter out .. and .
|
||||
$list = array_diff(scandir($dir), array('..', '.'));
|
||||
//now we can just use empty to check if the variable has any contents regardless of it's type
|
||||
if(empty($list)){
|
||||
echo 'dir is empty';
|
||||
}
|
||||
else{
|
||||
echo 'dir is not empty';
|
||||
}
|
||||
}
|
||||
else{
|
||||
echo 'not a directory';
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue