/    Sign up×
Community /Pin to ProfileBookmark

Check if specific folder contains files, folders, both or none ?

Good day to you all,
is there a way to check if a specific folder contains: files, folder, both or none ?

I read my folder with Glob, like my code here :

[code=php]

<?PHP
function globDir($dir)
{
$files = glob(“$dir/*”, GLOB_ONLYDIR);

if(!empty($files))
{
echo “<ul>n”;

foreach($files as $file)
{
echo “<li><b>”. basename($file).”</b>n”;
globDir($file);
echo “</li>n”;
}
echo “</ul>n”;
}
}
globDir(‘Photos’);
?>

[/code]

The only thing I have really found is how to find if a specific file exists.

I’m trying to find out if a specific folder contains : files, folders, both, none.
It would return the appropriate word accordingly.

Thanks and take care!

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@aj_nscFeb 27.2010 — [code=php]
$files = 0;
$dirs = 0;
$dir = "your/directory";
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
$dirs += (is_dir($file)) ? 1 : 0;
$files += (!is_dir($file)) ? 1 : 0;
}
}

//$files contains the number of files
//$dirs contains the numbers of directories
[/code]
×

Success!

Help @Peuplarchie spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...