Counting files in a folder

S

Steve Karnath

Is there a way to count how many file exist in a given folder on the server
using javascript. I realize javascript is client side scripting but i had to
ask
 
M

McKirahan

Steve Karnath said:
Is there a way to count how many file exist in a given folder on the server
using javascript. I realize javascript is client side scripting but i had to
ask

Does you Web sever support ASP?
 
S

Steve Karnath

Yes, but I have to restrict my code to javascript. Maybe very little asp
could be included.
 
M

McKirahan

Steve Karnath said:
Yes, but I have to restrict my code to javascript. Maybe very little asp
could be included.

ASP supports JavaScript.

The question is does your Web server support ASP?

Is the folder on the server under your web root?

<% Const cFOL = "your_folder"
Dim objFSO
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Dim objGFO
Set objGFO = objFSO.GetFolder(Server.MapPath(cFOL))
Response.Write(objGFO.Files.Count)
Set objGFO = Nothing
Set objFSO = Nothing
%>
 
M

McKirahan

Here the JScript version:

<%@ Language="JScript" %>
<% var cFOL = "your_folder"
var oFSO = new ActiveXObject("Scripting.FileSystemObject")
var oGFO = oFSO.GetFolder(Server.MapPath(cFOL))
Response.Write(oGFO.Files.Count)
%>
 
S

SBC Global

Thank you so much for your patience.
Yes the server supports ASP. The issue is that I am developing files to be
used on a .NET site where the all the code is compiled and my lack of
familiarity with .NET. I do not have access to the .NET project environment
because I am outside their firewall and they do not wish to open a portal to
allow access. Therefore just to be on the safe side and avoid any
compatibility issues I am trying to keep my server scripting to a minimum. I
hope this helps.

It appears that the code is still asp or is <%@ Language="JScript" %> <%
code here %> telling the javascript code to run at the server?
 
M

McKirahan

SBC Global said:
Thank you so much for your patience.
Yes the server supports ASP. The issue is that I am developing files to be
used on a .NET site where the all the code is compiled and my lack of
familiarity with .NET. I do not have access to the .NET project environment
because I am outside their firewall and they do not wish to open a portal to
allow access. Therefore just to be on the safe side and avoid any
compatibility issues I am trying to keep my server scripting to a minimum. I
hope this helps.

It appears that the code is still asp or is <%@ Language="JScript" %> <%
code here %> telling the javascript code to run at the server?

You didn't answer my question: "Is the folder on the server under your web
root?" If the folder is not under your Web root then you (or your
webmaster) will have to create a virtual folder to point to it.

Basically, just save my code to a file (say "Files.asp"); change the value
for "cFOL"; upload it to your Web server and open (say
http://{domain}/Files.asp).
 
M

McKirahan

[snip]

You might want to change it from
Response.Write(oGFO.Files.Count)
to
Response.Write(oGFO.Files.Count & " files in " & Server.MapPath(cFOL))
as it will be a little more meaningful for testing.
 
S

SBC Global

Yes my folder is under my web root.

McKirahan said:
You didn't answer my question: "Is the folder on the server under your
web
root?" If the folder is not under your Web root then you (or your
webmaster) will have to create a virtual folder to point to it.

Basically, just save my code to a file (say "Files.asp"); change the value
for "cFOL"; upload it to your Web server and open (say
http://{domain}/Files.asp).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top