10 examples of 'javascript list files in directory' in JavaScript

Every line of 'javascript list files in directory' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
3function searchFiles(directory, ignoreGlobPatterns = [], useGitIgnore = true) {
4 const config = { ignore: ignoreGlobPatterns, cwd: directory, useGitIgnore };
5 return new Promise((resolve, reject) => {
6 deglob('**/*', config, (err, files) => {
7 if (err) reject(err);
8 else resolve(files);
9 });
10 });
11}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

16function scanDirectory(directory){
17 fs.readdirSync(directory).forEach(function(filename){
18 appendFile(directory + '/' + filename);
19 });
20}
28function getFiles(dir, fileList = []) {
29 const files = fs.readdirSync(dir);
30 files.forEach((file) => {
31 const filePath = `${dir}/${file}`;
32 if (['.gitkeep', '.Trash-0', 'assets'].indexOf(file) === -1) {
33 if (fs.statSync(filePath).isDirectory()) {
34 getFiles(filePath, fileList);
35 } else {
36 const obj = {
37 path: filePath,
38 name: file,
39 type: file.split('.')[1],
40 }
41 fileList.push(obj);
42 }
43 }
44 });
45 return fileList;
46}
75function List (directory, store, start) {
76 var files = fs.readdirSync(directory);
77
78 for (var i = 0, length = files.length; i < length; i++) {
79 var filename = files[i];
80
81 if (!regexp.test(filename)) {
82 var filepath = path.join(directory, filename);
83
84 if (fs.statSync(filepath).isDirectory()) {
85 store = List(filepath, store, start);
86 } else {
87 store[filepath.substr(start)] = filepath;
88 }
89 }
90 }
91
92 return store;
93}
51function listSubdirectories(path) {
52 var files = fs.readdirSync(path);
53 var dirs = [];
54 for(i in files) {
55 var fullPath = path + '/' + files[i];
56 var stats = fs.statSync(fullPath);
57 if(!stats.isDirectory())
58 continue;
59 dirs.push(files[i]);
60 }
61 return dirs;
62}
20function searchFilesInDir(startPath, extension, recursive?: boolean) : string[] {
21 var result: string[] = []
22 if (!fs.existsSync(startPath)){
23 return result;
24 }
25
26 var files = fs.readdirSync(startPath);
27 for(var i = 0; i < files.length; i++){
28 var filename = path.join(startPath,files[i]);
29 var stat = fs.lstatSync(filename);
30 if (stat.isDirectory()){
31 if (recursive)
32 searchFilesInDir(filename, extension, recursive).forEach(i => result.push(i));
33 }
34 else if (filename.endsWith(extension)) {
35 result.push(filename);
36 }
37 }
38
39 return result;
40}
199function listDir (dir, filePattern, done) {
200 find.file(filePattern, dir, (files) => {
201 done(null, files)
202 })
203}
185async listFiles() {
186 const fileList = (await this.vault.listDirectory(this.name, null, false)).files;
187 for (let file of fileList) {
188 file.name = file.name.replace(/.json$/, '');
189 }
190 return fileList;
191}
132async function listMarkdownPaths (p) {
133 let results = []
134 let paths = await self.readdir(p, {recursive: true})
135 return paths.filter(p => p.endsWith('.md'))
136}
3export default function getDirectoryList(list) {
4 return _.map(list, e => e.Prefix.split("/").slice(-2)[0]);
5}

Related snippets