Solved

Get Sub-Folders Using JavaScript

Posted on 2010-09-17
13
524 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
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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 108

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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)

911 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now