Skip to content

Commit fa8d9ed

Browse files
committed
Should now sort the files by date last modified. Command done
1 parent 56c3f55 commit fa8d9ed

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

commands/factorio/restoreSave.js

+14-4
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,28 @@ module.exports = {
4747
)
4848
let dir = '../servers/'+args[0]
4949
let dirData = fs.readdirSync(dir) // add in all file names that end with .zip
50-
dirData = bubbleSort(dirData);
50+
51+
//sort dirData by date last modified
52+
dirData = dirData.map(function (fileName) {
53+
return {
54+
name: fileName,
55+
time: fs.statSync(dir + '/' + fileName).mtime.getTime()
56+
};
57+
})
58+
.sort(function (a, b) {
59+
return a.time - b.time; })
60+
.map(function (v) {
61+
return v.name; });
62+
63+
5164
for (let i = 0; i < 25; i++) { // max number of fields in a Discord Embed is 25
5265
if (!dirData[i]) break;
5366
if (dirData[i] && dirData[i].endsWith('.zip')) {
5467
let data = fs.statSync(dir+'/'+dirData[i])
5568
let date = new Date(data.birthtimeMs)
56-
dataDic[dirData[i]] = date.toUTCString();
5769
}
5870
}
5971

60-
// somehow sort dirData and date pairs by the newest date
61-
6272
choiceEmbed.addField(`\`${dirData[i]}\``, `Save created on: ${date.toUTCString()}`);
6373

6474
return message.channel.send(choiceEmbed)

0 commit comments

Comments
 (0)