Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Get Sub-Folders Using JavaScript

Posted on 2010-09-17
13
Medium Priority
?
538 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
  • 5
  • 3
  • 2
  • +2
12 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 83

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

 
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 83

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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
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 dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

564 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