Lan Mai
Lan Mai

Reputation: 375

Get Folder Javascript

Is there a way in Javascript that we can get a folder in the root folder to a variable then use .getFiles() to get the files in that folder?

I worked with scripting in Photoshop with Javascript and these codes works:

Destination = Folder ('G:/My Projects/Project 2/Sounds');
Files = Destination.getFiles();

But in web developing it does not work. Is there a way? Thank you.

Is there a way that I can use paths like ('/Sounds') ?

Upvotes: 2

Views: 2256

Answers (2)

Pbd
Pbd

Reputation: 1319

No. For your web browser, the root of the folder starts at html page you are serving. Only those directories and sub-directories which lie within the same folder as the html page can be accessed. To achieve what you desire, you probably need to write a server too.

yeah. if you have following directory structure

/(root1)
|--file1
/(root)
 |--index.html
 |--dir1/
 |--dir2/
 \--dir3/
   |--file

Only dir1,dir2 and dir3 contents can be accessed. file1 can't be accessed.

Upvotes: 4

nem035
nem035

Reputation: 35491

The browser doesn't allow you to access the file system due to security reasons.

What if any page you visit could do this?

// over simplified example
var passwords = File('C:/passwords.txt'); 

Upvotes: 1

Related Questions