-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetFiles.js
More file actions
32 lines (27 loc) · 915 Bytes
/
getFiles.js
File metadata and controls
32 lines (27 loc) · 915 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
//node getFiles.js
const fs = require('fs');
const path = require('path');
function getFiles(dirPath, callback) {
fs.readdir(dirPath, function (err, files) {
if (err) return callback(err);
files.forEach(function (file) {
let fullPath = path.join(dirPath, file);
fs.stat(fullPath, function (err, fileInfo) {
if (err) return callback(err);
if (fileInfo.isDirectory()) {
getFiles(fullPath, callback);
} else {
callback(undefined, fullPath);
}
});
});
});
}
if (fs.existsSync('file-list.txt')) {
fs.unlinkSync('file-list.txt');
}
getFiles('.', function (err, filePath) {
if (err) throw err;
let formattedPath = `'/minigame-collection/${filePath.replace(/\\/g, '/')}',\n`;
fs.appendFileSync('file-list.txt', formattedPath);
});