Created
April 12, 2021 15:07
-
-
Save mrocha98/93734faafb28988f6749c0cd76fac319 to your computer and use it in GitHub Desktop.
Revisions
-
mrocha98 created this gist
Apr 12, 2021 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ 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) } })()