1

I know that and I have try use PHP5 before to get the textfile name inside a folder.

$directory = "/C/Home/Newfolder";
$file = scandir($directory);
print_r($file);

These program will read the content inside Newfolder file, and list out all the text file name. I wish HTML5 or Javascript also can do that, did you guys have any good suggestion just like "scandir" in PHP5 ?

Mention** Only Javascript/HTML5

Example : Inside Newfolder it consist of

a.txt, b.txt, c.txt, d.txt

I wish to get all the name only ~

Jackdon Chew
  • 117
  • 1
  • 2
  • 10
  • 1
    Possible duplicate of [Local file access with javascript](http://stackoverflow.com/questions/371875/local-file-access-with-javascript) – Justinas Apr 10 '17 at 07:03
  • My intention is to scan the filename inside a folder, not access the file. I just want to get the textfile name – Jackdon Chew Apr 10 '17 at 07:07
  • Also, do you wish to access file that is located on server or on user local file system? Your example will list only server-owned files. – Justinas Apr 10 '17 at 07:31

1 Answers1

1

I do not understand the question well. Does this need to be done from the end user's browser or is it a server side operation?

The operation that you show in your question with PHP5, is a server-side operation.. You can do that with NodeJS using the method fs.readdir(path[, options], callback):

const fs = require('fs');
const directory = '/C/Home/Newfolder/';

// Get array of files name in directory folder
fs.readdir(directory, (err, files) => {
  // logs all file names..
  files.forEach(fileName => {
    console.log(fileName);
  });
});
Yosvel Quintero
  • 18,669
  • 5
  • 37
  • 46