Skip to content

Instantly share code, notes, and snippets.

@yeungon
Created August 23, 2023 10:17
Show Gist options
  • Save yeungon/0c8111bf28b9ce48ea509e24ad10d20b to your computer and use it in GitHub Desktop.
Save yeungon/0c8111bf28b9ce48ea509e24ad10d20b to your computer and use it in GitHub Desktop.
const fs = require("fs");
const path = require("path");
const folderPath = __dirname + "/MBall_sections_applx_RAs_MARKUP";
const outputFolderPath = __dirname + "/conclusion";
fs.readdir(folderPath, (err, files) => {
if (err) {
console.error("Error reading folder:", err);
return;
}
files.forEach((file, index) => {
const filePath = folderPath + "/" + file;
fs.readFile(filePath, "utf8", (err, data) => {
if (err) {
console.error("Error reading file:", err);
return;
}
let markup1 = `<C>`;
let markup2 = `</C>`;
let beginning = data.indexOf(markup1);
let ending = data.indexOf(markup2);
let sliced = data.substring(beginning, ending);
const stringWithoutSpaces = file.replace(/\s+/g, "");
const fileName = `${outputFolderPath}/${stringWithoutSpaces}`;
try {
fs.writeFileSync(fileName, sliced);
} catch (err) {
console.error(err);
}
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment