Skip to content

Instantly share code, notes, and snippets.

@mrocha98
Created April 12, 2021 15:07
Show Gist options
  • Select an option

  • Save mrocha98/93734faafb28988f6749c0cd76fac319 to your computer and use it in GitHub Desktop.

Select an option

Save mrocha98/93734faafb28988f6749c0cd76fac319 to your computer and use it in GitHub Desktop.

Revisions

  1. mrocha98 created this gist Apr 12, 2021.
    24 changes: 24 additions & 0 deletions remove-spaces.js
    Original 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)
    }
    })()