PDA

View Full Version : CGI to count number of files in Server Side directory


tim8w
02-14-2005, 06:29 AM
I need to count the number of files in a directory. What I really need to do is to have the directory passed in from a JavaScript function and return the number of files to the JavaScript funtion.

Thanks,
Tim

OkIDaN
02-14-2005, 08:26 AM
I need to count the number of files in a directory. What I really need to do is to have the directory passed in from a JavaScript function and return the number of files to the JavaScript funtion.

Thanks,
Tim
In CGI script it would look lie this:

@files=<./directory/*>;
$num=$#files+1;

# $num has number of files in 'directory'

tim8w
02-14-2005, 08:34 AM
OkIDaN,

How do you call this CGI?

JavaScript:

var iNumFiles = "http://www.mysite.com/cgi-bin/fileCount.cgi?directory/subdirectory"



or something like that?

OkIDaN
02-14-2005, 01:15 PM
Uhm, not exactly. Thats a whole story. The first step is to open a nice tutorial or the CGI chapter in one of those O'reilly books and read it. I thought you are asking about implementing it to a cgi script. If you are asking how to do it in Javascript, then this is probably the wrong section of the forum.

Dude-21
04-13-2005, 09:43 PM
How Do you count the total number of files in a directory with php?

( found this topic from: http://www.google.com/search?hl=en&safe=off&client=firefox-a&rls=org.mozilla:en-US:official&q=count+the+number+of+files+in+a+directory&spell=1 ) ^^