Get Sub-Folders Using JavaScript

How do you get sub-folders using JavaScript?  I want to get the sub-folders of a particular folder.
Ray TurnerSenior ConsultantAsked:
Who is Participating?
 
ZvonkoConnect With a Mentor Systems architectCommented:
Store this script in a file with extention .js and execute it:

var allSubFolders = [];
var fso = new ActiveXObject("Scripting.FileSystemObject");
var fdir = fso.GetFolder("C:\\Windows");
for(var objEnum = new Enumerator(fdir.SubFolders); !objEnum.atEnd(); objEnum.moveNext()) {
  strFolderName = objEnum.item().Name;
  allSubFolders.push(strFolderName);
}
WScript.Echo(allSubFolders.join("\t"));

0
 
Ray TurnerSenior ConsultantAuthor Commented:
Can this be done without using ActiveXObject?
0
 
leakim971Connect With a Mentor PluritechnicianCommented:
>Can this be done without using ActiveXObject?

No, Javascript don't allow you to play with the user ressources like disk.
Only with JScript and ActiveX (so only on IE) you can access computer ressources like folders infos, files, etc...
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
ZvonkoSystems architectCommented:
Can you state why you want to do this without ActiveXObject?
0
 
Ray TurnerSenior ConsultantAuthor Commented:
Just curious.
0
 
VeganBenCommented:
Can you state why you want to do it at all?

It's a deliberate security restriction and if you get around it, congratulations, you've just blown a pretty big security hole in which ever browser you manage to achieve it in.
Except IE, of course. Which, as it has been pointed out, explicitly allows you to do this.

0
 
Ray PaseurCommented:
I'm with VeganBen 100% on this one.  Can you tell us what your application needs to do (in high-level terms)?  If we understand that we may be able to help better.  If you're planning to write a PHP script that gets information off of the client computer you may find it's not easy or consistent.  There are two sides to the client / server architecture, and security paradigms (except for Microsoft whose designs brought forth the computer worm) try to separate the two sides, using formal interfaces.  Example: You cannot prepopulate the value of <input type=FILE>
0
 
ZvonkoConnect With a Mentor Systems architectCommented:
> Just curious.

OK. JavaScript is a scripting language that does not have disk access methods built in like other scripting languages.
Therefore to get access to files you need to load external methods to do so.
If you want to do JavaScript in Windows Scripting Host (WSH) then you have to load the ActiveX extensions to be able to call the interfaces of those extensions to access operating system resources.
Files can be accessed either by upper FileSystemObject or by external command processors. In any case as soon as you load such extension then such scripts can be run only in user context and never in server page context. The server page context runs in so called SandBox model where no access to local resources is allowed.

So as long as you hide what your intentions are so long you will get only philosophical approaches according to our assumptions.
0
 
ZvonkoSystems architectCommented:
There is no visible reason why the asker wants to reduce the offered points.
The question is fully answered and therefore no reason to reduce points.
0
 
Ray TurnerSenior ConsultantAuthor Commented:
Thanks.  The answer was adequate.
0
 
leakim971PluritechnicianCommented:
Thanks for the points!
0
 
ZvonkoSystems architectCommented:
I beg a pardon for my confusion comments <|:-)
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.