1

I have a file server located at say http://myshare.com. This server is used to just host all my files. My file server has a directory named 'myfiles'. So my URI looks something like this: 'http://myshare.com/myfiles'. This location has say 10 files.

First question: How do I get the names of all the files located on this remote file server using Node.js?

Second question: If 'myfiles' directory has sub-directories, how do I traverse all the sub-directories and list all the files in them using Node.js?

Any help would be appreciated. Thanks

user1999645
  • 107
  • 1
  • 3
  • 6

1 Answers1

0

I suppose that the files are on the same machine, since you can always mount them with cifs or similar and then it would be the same than local files, making live easier since is OS who manages them instead of your code.

First, you have to familiarize with node's file object anf the function "readdir" either on its async or sync version. http://nodejs.org/api/fs.html#fs_fs_readdir_path_callback

Then you parse the array of files returned .

For subdirectories you have to code a recursive function that calls itself on every directory. For every file you have to check the fsstats and check the property isDirectory() over the returned object.

As a sample, you can check this answer https://stackoverflow.com/a/5827895/1680125

Hope it helps

Community
  • 1
  • 1
JR.
  • 1,401
  • 1
  • 11
  • 9
  • My files are present on a remote server and not on the same machine. I need to get the names of all the files present on that server through my javascript code. I have checked a number of answers but none suffice to what I am looking for. – user1999645 Jan 30 '13 at 05:42