Need smiple Code For counting files on media card then add value to html form

Need smiple Code For counting files on media card then add value to html form.

I need help creating a code that will count the number of files in a folder, then with the information fill a form field with the number so it will be submited with the form.
kwitcomAsked:
Who is Participating?
 
jaydeeukConnect With a Mentor Commented:
I have done something similar across a network. All it did was look for files on computers and index them in to a database. Saying that browsers do not have access to the local file system is not strictly true.
The easiest way is to make the drive a shared resource with read access (Iwam account and Iusr)
Then make a variable in ASP telling the code where the share is located, and then as someone suggested, use the filesystem object to loop thru all the directories (recursive loop will work best) indexing all the files, and write out the total.


Another way would be using a HTA application. This gets round most of the security problems with normal HTML pages and gives you full access to the local file system. The limitations of this is that the HTA will probably need to be run on the same computer as the one with the drive you wish to access, although i have never tried to access a remote computer (assuming you have full read/write privilages)

0
 
RoonaanConnect With a Mentor Commented:
kwitcom,

Although my knowledge on this matter is somewhat limited, the one thing I can tell you is that when security does its job, you would not be able to do this using clientside scripting.
Using serverside languages which have access to the media card, you would be able to count files and output the number of files using a generated form, but in general, languages like javascript or vbscript cannot perform this task.

-r-
0
 
kwitcomAuthor Commented:
Well this is on a Private network that i have full access on and i can change the rights to do what i want.
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
COBOLdinosaurConnect With a Mentor Commented:
Ihas nothing to do with rights or privileges.  By design browsers pages no not hav acess to client resources.  It would be such a huge security hole that it is not optional and there is not setting that can be changed.  

However if the page is served up from the local computer using a file: protocol then you can access the hard drive, but you will still need programming to get what yo want becasue conventional client web page languages do not have the methods necessary to interact with the file systemon local computer except to make simple load request.  you will have to embed some Java or activex to get what you want

Cd&
0
 
RoonaanConnect With a Mentor Commented:
Using the suggestion on local file systems by COBOLdinosaur you could try using vbscript and
createObject("scripting.FileSystemObject");
However I am not sure wether or not this would be working without needing a lot of tweaks.

-r-
0
 
COBOLdinosaurConnect With a Mentor Commented:
Yeah fso is usable aslong as activex is enabled.

Wsh as well.

Cd&
0
 
kwitcomAuthor Commented:
Well this is being run from the local system that i have installed IIS on to be able to run the page... Another option might be to run a script when the page loads that counts and creates a pop-up with the number which the user can re-type into the form.
0
 
COBOLdinosaurConnect With a Mentor Commented:
>>>Saying that browsers do not have access to the local file system is not strictly true.

As a matter of fact, no one said that.  It was indicated that browser pages do not have access to client resources.  That is 100% accurate.  

When a web page is served from the file system on a local machine, the file system is host the browser pages still do not have access.  When HTA is used the windows is the host.  When FSO is used; that is an active x object.  For Any ASP solution it is obvious that the web page is not the agent of access because ASP runs on the host server.

So let's try and keep thesemantics accurate;  especially when we are dealing with M$ only solutions that bypass normal security, and invite developer to build things that cannot be suppoert outside of the narow place they built it in.

Cd&
0
 
kwitcomAuthor Commented:
This is what i found to use.... i have it saved as a .vbs file and i can edit to the path i need.

File: c1.vbs

Set fs = CreateObject("Scripting.FileSystemObject")
folderName = "c:\music"
Wscript.echo fs.GetFolder(folderName).Files.Count

output: 2xxxxxx

This works great... it is a popup box but works.... Thanx all for help
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.