Skip to content

Instantly share code, notes, and snippets.

@vabene1111
Created January 2, 2018 19:39
Show Gist options
  • Save vabene1111/394cb09039d97d1a6022fdc528b5afeb to your computer and use it in GitHub Desktop.
Save vabene1111/394cb09039d97d1a6022fdc528b5afeb to your computer and use it in GitHub Desktop.
// npm install recursive-readdir
var recursive = require("recursive-readdir");
var path = require('path');
var fs = require('fs');
function ignoreFunc(file, stats) {
return !stats.isDirectory() && path.extname(file) != ".sqf";
}
var mission = "test"; // path to folder
recursive(mission, [ ignoreFunc ] ,function (err, files) {
for (var i = files.length - 1; i >= 0; i--) {
var file = files[i];
var data = fs.readFileSync(file); //read existing contents into data
var fd = fs.openSync(file, 'w+');
var buffer = new Buffer('#define file_name "' + path.basename(file) + '"\n');
fs.writeSync(fd, buffer, 0, buffer.length, 0); //write new data
fs.writeSync(fd, data, 0, data.length, buffer.length); //append old data
fs.close(fd);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment