[thelist] Counting files in a folder using JavaScript
Ben Gustafson
ben_gustafson at lionbridge.com
Tue Dec 11 08:25:02 CST 2001
> Hey all,
>
> Is there a quick and easy way to count files in a folder and
> assign the
> number to a var in JavaScript?
>
> -d
Dave,
Here's a quick and easy way to use the FileSystemObject in ASP to count the number of
files in a folder and pass this server-side info to client-side JavaScript:
--
<%
var filesCount = 0;
var strPath = "c:\\path\\to\\your\\folder";
countFiles(strPath);
function countFiles(strPath)
{
var objFSO = Server.CreateObject("Scripting.FileSystemObject");
var objFolder = objFSO.GetFolder(strPath);
var objFiles = objFolder.Files;
filesCount = objFiles.Count;
objFolder = null;
objFiles = null;
objFSO = null;
}
%>
<SCRIPT LANGUAGE="JavaScript1.2"><!--
var numFiles = "<%= filesCount %>";
//--></SCRIPT>
--
I imagine most any other server technology can do a similar thing.
--Ben Gustafson
Lionbridge Technologies
www.lionbridge.com
More information about the thelist
mailing list