0

I am trying to automate an Angular application using Protractor and I came across a scenario where I need to list all the files present inside a folder.

I know in Java we can use the following:

File f = new File('D:\Practice');
ArrayList<String> names = new ArrayList<String>(Arrays.asList(f.list()));

But i couldnt get a solution in Javascript.

4
  • This is going to depend on your JS environment. For example, this is going to be close to impossible from a browser. It is usually not considered a good thing if a web page can enumerate files on your computer. Commented Jun 17, 2014 at 13:07
  • You're gonna need a back-end tech in order to access files. In Node.js, you would use fs.readdir("path", function(err, files) { ... }) Commented Jun 17, 2014 at 13:08
  • You can access FS from protractor script but not from the browser. Commented Jun 17, 2014 at 13:09
  • You should be more specific and provide more details on the use case. Commented Jun 17, 2014 at 13:15

1 Answer 1

1

Node.js File System readdirSync
https://nodejs.org/dist/latest-v10.x/docs/api/fs.html#fs_fs_readdirsync_path_options

var fs = require('fs');
var files = fs.readdirSync('/tmp'); // returns list of filename as an array
Sign up to request clarification or add additional context in comments.

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.