Last active
January 4, 2025 07:47
-
-
Save delasy/e15f3ec5971a7ca33d9dac713ad83100 to your computer and use it in GitHub Desktop.
Check files in current folder start with a certain content (Node.js)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require("node:fs"); | |
const path = require("node:path"); | |
const banner = `<text-goes-here>`; | |
const exclusions = ["Dockerfile", "build"]; | |
function traverseFolder (folderPath) { | |
const realFolderPath = fs.realpathSync(folderPath); | |
const entries = fs.readdirSync(realFolderPath, { withFileTypes: true }); | |
for (const entry of entries) { | |
if (entry.name.includes(".") || exclusions.includes(entry.name)) { | |
continue; | |
} | |
const entryPath = entry.parentPath + entry.name; | |
if (entry.isDirectory()) { | |
traverseFolder(entryPath); | |
continue; | |
} | |
const content = fs.readFileSync(entryPath, "utf8"); | |
if (!content.startsWith(banner)) { | |
console.log(entryPath); | |
} | |
} | |
} | |
traverseFolder(process.cwd()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment