2

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') ?

1
  • you are mixing 2 environments together ;) Commented Feb 3, 2017 at 4:00

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

4 Comments

Is there a way that I can use paths like ('/Sounds') ?
yeah. if you have following directory structure / |--index.html |--dir1/ |--dir2/ \--dir3/ |--file
Hi, can you show me the right way for the 'syntax' ? Like if I want to access dir3, I use 'Destination = Folder('dir3')' ?
what exactly is the requirement?
1

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'); 

2 Comments

Is there a way that I can use paths like ('/Sounds') ?
You can look at a directory through the browser using the file protocol. For example file://path/to/Sounds

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.