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.

gontard
  • 28,720
  • 11
  • 94
  • 117
Vinay Sagar
  • 21
  • 3
  • 9
  • 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. – Dark Falcon Jun 17 '14 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) { ... })` – ndugger Jun 17 '14 at 13:08
  • You can access FS from protractor script but not from the browser. – gontard Jun 17 '14 at 13:09
  • You should be more specific and provide more details on the use case. – gontard Jun 17 '14 at 13:15

1 Answers1

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
martin770
  • 1,271
  • 11
  • 15