Created
April 12, 2021 15:07
-
-
Save mrocha98/93734faafb28988f6749c0cd76fac319 to your computer and use it in GitHub Desktop.
A Node.js script that remove spaces from filenames and replace for dashes
This file contains 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 path = require('path') | |
const { promises: fs } = require('fs') | |
const DIR = '.' | |
const spacesRegex = /\s/g | |
;(async () => { | |
try { | |
const files = await fs.readdir(DIR) | |
for (const file of files) { | |
const stat = await fs.stat(file) | |
const IS_NOT_FILE = !stat.isFile() | |
if (IS_NOT_FILE) continue | |
const oldPath = path.join(DIR, file) | |
const newPath = path.join(DIR, file.replace(spacesRegex, '-')) | |
await fs.rename(oldPath, newPath) | |
} | |
} catch (err) { | |
console.log(err) | |
} | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment