Reputation:
I am using windows and have this folder:
c:\myfiles
Inside that directory I have some files.
So:
getfilesList() {
mypath: 'c:\myfiles'
// code to get file list here
}
How can I do this?
ps: I found quite a few examples but none worked for me for one reason or another.
Upvotes: 0
Views: 521
Reputation: 13782
If you write a local tool and need not asynchronous methods, you can just use fs.readdirSync()
. Do not forget to escape Windows delimiters in your path:
const fs = require('fs');
const filenamesArray = fs.readdirSync('C:\\Program Files\\nodejs');
console.log(filenamesArray);
Output:
[ 'install_tools.bat',
'node.exe',
'nodevars.bat',
'node_etw_provider.man',
'node_modules',
'npm',
'npm.cmd',
'npx',
'npx.cmd' ]
Upvotes: 0
Reputation: 229
You should read the documentation of fs
(FileSystem) in the Node website
The function you search is fs.readdir(yourPath)
Hope this help!
Upvotes: 1