[thelist] Counting files in a folder using JavaScript
Burhan Khalid
burhankh at hotmail.com
Tue Dec 11 08:32:25 CST 2001
I believe the man said JavaScript. If my memory serves me correctly, don't
security restrictions prohibit javascript from accessing files?
--Burhan Khalid
> Hey all,
>
> Is there a quick and easy way to count files in a folder and
> assign the
> number to a var in JavaScript?
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
--
For unsubscribe and other options, including
the Tip Harvester and archive of TheList go to:
http://lists.evolt.org Workers of the Web, evolt !
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp
More information about the thelist
mailing list