0

Is there a way that i can get all the files and directories on the server using js? Lets say there is a folder on the server called Files, inside the files folder, there are other folders and files but not a set value and can change constantly. Is there a way to scan the Files folder?

2

2 Answers 2

0

you can achieve this wiht a server side script, for example PHP http://php.net/manual/en/function.scandir.php

this function returns the dirs, you could nested to get all the dirs and files in directories then you can return to the javasript with

<? echo json_ecnode($array_with_dirs);?>

with an ajax Request

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

Comments

0

If you are asking about client-side JavaScript only, no, you cannot do that. You can read URLs using Ajax. If a URL corresponds to a file, you've read the file. If a URL corresponds to a directory and the server responds server-generated index, you could parse that index and recursively read files and indices. The "crawler" programs used by, e.g. Google, employ a similar technique, but do not depend on server-generated indices; they just follow links.

If the files you ask about are not accessible to the web server program, i.e. outside the server's document root, then you cannot read them using only client-side code.

Comments

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.