/    Sign up×
Community /Pin to ProfileBookmark

Find out number of files in a folder

Hello everyone:

I’m using PHP script on a UNIX/LINUX platform (via shared web hosting). Can someone suggest how to determine number of files in a certain folder. (I have full access to that folder.)

Thank you.

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJun 20.2006 — Do you want the total number just of files, or should sub-directory names be counted, too?
Copy linkTweet thisAlerts:
@shane_carrJun 20.2006 — (untested)

[code=php]
$files = glob("*");
$numberoffiles = count($files);
echo("There are $numberoffiles files in your directory");
[/code]


it's a start
Copy linkTweet thisAlerts:
@NogDogJun 20.2006 — Or, if you like your code dense:
[code=php]
$directory = "/foo/bar";
printf("<p>The number of files in %s is %d.</p>n", $directory, count(glob("$directory/*")));
[/code]

?
Copy linkTweet thisAlerts:
@dc2000authorJun 21.2006 — Thanks guys!

glob() is what I was looking for. Love PHP, it's so easy ?
×

Success!

Help @dc2000 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.18,
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,
)...