/    Sign up×
Community /Pin to ProfileBookmark

use javascript to count

Hi there,

Can anyone please tell if I can use javascript to count how many files one folder has. If I can, how?

I need to make a ‘next’ button, to indicate user to go to next page until there’s no more. this is a CD which will be used offline, so I will onlt be able to use HTML and javascript…

Thanks a lot

to post a comment
JavaScript

13 Comments(s)

Copy linkTweet thisAlerts:
@JonaFeb 22.2005 — [font=trebuchet ms]You can do it if it's on a local hard drive (and not the Internet), but only with Internet Explorer (and the ActiveX plugin known as the File System Object).[/font]
Copy linkTweet thisAlerts:
@jakykongFeb 22.2005 — no, you can't... the FileSystemObject is server code, JavaScript can't do it.... what could is if you had an intranet running only one computer, so that ASP is processed by the computer it's requested on. I do that to test my ASP pages before i post them, but JavaScript itself doesen't have access to the FSO... or any activex for that matter!

i could be wrong, i often am ... prove me wrong!
Copy linkTweet thisAlerts:
@JonaFeb 22.2005 — [i]Originally posted by jakykong [/i]

[B]no, you can't... the FileSystemObject is server code, JavaScript can't do it.... what could is if you had an intranet running only one computer, so that ASP is processed by the computer it's requested on. I do that to test my ASP pages before i post them, but JavaScript itself doesen't have access to the FSO... or any activex for that matter!



i could be wrong, i often am ... prove me wrong! [/B]
[/QUOTE]


[font=trebuchet ms]If the HTML files are on a CD, you can open them in Internet Explorer where JavaScript can be executed. The FSO is an ActiveX object that gives JavaScript access to the filesystem of the computer which it is runnning on. Search the Microsoft Developer's Network for documentation on it and all that wonderful stuff. ? [/font]
Copy linkTweet thisAlerts:
@PittimannFeb 22.2005 — Hi!

And here is an example demonstrating that it works:[code=php]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Example</title>
<script language="JavaScript" type="text/javascript">
<!--
var fileNameArray= new Array();
count=0;
function getFiles(){
var fso = new ActiveXObject("Scripting.FileSystemObject");
folderObj = fso.GetFolder("c://");
fileArr=folderObj.Files
var files = new Enumerator(folderObj.Files);
for (; !files.atEnd(); files.moveNext()){
fileName=''+files.item();
fileNameArray[count]=fileName;
count++;
}
str='Number of files: '+fileNameArray.length+'<br><br>';
for (var i=0;i<fileNameArray.length;i++){
str+=fileNameArray[i]+'<br>';
}
document.getElementById('show').innerHTML=str;
}
//-->
</script>
</head>
<body onload="getFiles()">
<div id="show"></div>
</body>
</html>[/code]
Cheers - Pit
Copy linkTweet thisAlerts:
@jakykongFeb 22.2005 — um, ok. Well, that's nice to know - learn something every day!

i'm always open to learn something new, i am not offended by people correcting my mistakes (except when they do so saying i am an idiot who knows nothing).

I do get an ego sometimes, but who doesen't, although when i've worked for an hour figuring out a piece of code, don't expect me to back down!
Copy linkTweet thisAlerts:
@jakykongFeb 22.2005 — one thing does come to mind, though .... since JavaScript is run by the browser, does it matter where it originated?
Copy linkTweet thisAlerts:
@PittimannFeb 22.2005 — Hi!

We're ALL here to learn and if there is someone around claiming to already know everything, he/she is mistaken.

Cheers - Pit
Copy linkTweet thisAlerts:
@virtualauthorFeb 23.2005 — Hi Guys,

Thank you so much for spending time answering my question. So now I know that this can be done, which is great! I'm going to start writing the script then, with my books open:-) very new to javascript.

I'm not sure if my script will work well, I probably have to come back to see you guys with my script if it's not working...It's really nice to know that there are many people here trying to help other people out. I really appreciate it. Thanks again guys.

Good luck to me..:-)

Cheers
Copy linkTweet thisAlerts:
@PittimannFeb 23.2005 — Hi![i]Originally posted by virtual [/i]

[B]Good luck to me..:-)



Cheers [/B]
[/QUOTE]
Yes! Good luck to you. ?

Cheers - Pit
Copy linkTweet thisAlerts:
@virtualauthorFeb 27.2005 — Hi guys,

I have spent a couple days to think how i am going to start making this CD. It's a CD catalog kind of thing. It need to allow users to do catagory searching and keyword searching. Also I need to display images as search results.(certain number images each page adn up to 40 page for a catagory..:-(

It does seem like a lot work if I get it all done manually. I searched in Google. There are actually a lot of CD catalog software out there, around $US70. What do you think? should I use one of them? Or do you know any software what can do the same job but cheaper? really, I don't need all the features those sofeware offer, i only need the basic features. Do you think that I should stick to making my own?

any suggestion? Pit? anyone?

Thanks :-)
Copy linkTweet thisAlerts:
@herodote92Feb 27.2005 — "It works"...

Yes, it does, but the Norton Antivirus message is so frightening that you don't really feel like trying it.
Copy linkTweet thisAlerts:
@virtualauthorMar 03.2005 — what Norton Antivirus message?
Copy linkTweet thisAlerts:
@herodote92Mar 03.2005 — When I use such things, I always get a frightening Norton message, "Malicious script detected !" if I remember well. You are allowed to bypass it and the thing will work, but I guess a normal user would think twice before bypassing it.
×

Success!

Help @virtual spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.1,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...