Solved

Get Sub-Folders Using JavaScript

Posted on 2010-09-17
13
527 Views
Last Modified: 2012-05-10
How do you get sub-folders using JavaScript?  I want to get the sub-folders of a particular folder.
0
Comment
Question by:Ray Turner
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
  • +2
13 Comments
 
LVL 63

Accepted Solution

by:
Zvonko earned 333 total points
ID: 33705887
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
 

Author Comment

by:Ray Turner
ID: 33705927
Can this be done without using ActiveXObject?
0
 
LVL 82

Assisted Solution

by:leakim971
leakim971 earned 167 total points
ID: 33706468
>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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 63

Expert Comment

by:Zvonko
ID: 33707063
Can you state why you want to do this without ActiveXObject?
0
 

Author Comment

by:Ray Turner
ID: 33707576
Just curious.
0
 
LVL 3

Expert Comment

by:VeganBen
ID: 33707591
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
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 33708274
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
 
LVL 63

Assisted Solution

by:Zvonko
Zvonko earned 333 total points
ID: 33708972
> 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
 
LVL 63

Expert Comment

by:Zvonko
ID: 33713930
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
 

Author Comment

by:Ray Turner
ID: 33715365
Thanks.  The answer was adequate.
0
 
LVL 82

Expert Comment

by:leakim971
ID: 33760300
Thanks for the points!
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 33760488
I beg a pardon for my confusion comments <|:-)
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question