?
Solved

Get Sub-Folders Using JavaScript

Posted on 2010-09-17
13
Medium Priority
?
533 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 1332 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 668 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 111

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 1332 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

Technology Partners: 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!

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

762 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