I have created a function that does this:
var getMostRecent = function (dir: string, cb: any) {
var dir = homedir
var files = fs.readdir(dir, function (err, files) {
var sorted = files.map(function(v) {
var filepath = path.resolve(dir, v);
return {
name:v,
time:fs.statSync(filepath).mtime.getTime()
};
})
.sort(function(a, b) { return b.time - a.time; })
.map(function(v) { return v.name; });
if (sorted.length > 0) {
cb(null, sorted[0]);
} else {
cb('Roblox appears to not be installed. Why do you plan to restore the old Roblox cursor, when Roblox doesn't even exist?', null);
}
})
}
Then I call the function like this:
var recent = getMostRecent('./', function (err: any, recent: any) {
if (err) console.error(err);
return {
recent: recent
}
});
console.log(recent);
But then I get undefined. When I run this:
getMostRecent('./', function (err: any, recent: any) {
if (err) console.error(err);
console.log(recent);
});
It gives the folder. I can’t figure out a way to return this value.
Maybe I’m too used to Lua.