Skip to content

Instantly share code, notes, and snippets.

@vilindberg
Last active March 28, 2019 15:59
Show Gist options
  • Select an option

  • Save vilindberg/d299166d60b239dbd1121d2a7059b4b2 to your computer and use it in GitHub Desktop.

Select an option

Save vilindberg/d299166d60b239dbd1121d2a7059b4b2 to your computer and use it in GitHub Desktop.
const fs = require('fs')
const path = require('path')
function logFiles(dir, excludes) {
for (const fileName of fs.readdirSync(dir)) {
const filePath = path.resolve(dir, fileName)
const stats = fs.statSync(filePath)
if (excludes.some(exclude => filePath.includes(exclude))) {
continue
}
if (stats.isDirectory()) {
logFiles(filePath, excludes)
} else {
if (filePath.includes('.js')) {
const newFilePath = filePath.replace('.js', '.ts')
fs.rename(filePath, newFilePath, () => {
console.log(`RENAMED ${filePath} to ${newFilePath}`)
})
}
}
}
}
logFiles(`${__dirname}/random-folder`, ['random-folder-1', 'random-folder-2'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment