/    Sign up×
Community /Pin to ProfileBookmark

How to count folder files using php

hai friends

I need to count the files with in the selected folder.

How to count the files ?? please help me. If any paossibel ple4ase send me sample code.

Thanks
vssp

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@pcthugOct 24.2006 — Try this function I created:[code=php]<?php
/*
int count_file ( string dir )

*/
function count_file($dir)
{
if(!is_dir($dir))
return user_error('dir parameter must be a directory', E_USER_ERROR);

$i = 0;

if($handle = opendir($dir))
{
while(false !== ($filename = readdir($handle)))
{
if($filename != '.' && $filename != '..')
$i++;
}
}

return $i;
}

echo count_file('C:\');

?>[/code]
Copy linkTweet thisAlerts:
@bokehOct 24.2006 — Assuming the files follow the accepted naming convention: [code=php]$file_count = count(glob($path.'*.*'));[/code]
Copy linkTweet thisAlerts:
@vsspauthorOct 25.2006 — Thanks for your replay


vssp
×

Success!

Help @vssp 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 6.16,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...