Last active
April 10, 2023 23:30
-
-
Save scriptex/20536d8cda36221f91d69a6bd4a528b3 to your computer and use it in GitHub Desktop.
Revisions
-
scriptex revised this gist
May 26, 2019 . 1 changed file with 8 additions and 10 deletions.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 @@ -1,18 +1,16 @@ const { join } = require('path'); const { readdirSync, renameSync } = require('fs'); const [dir, search, replace] = process.argv.slice(2); const match = RegExp(search, 'g'); const files = readdirSync(dir); files .filter(file => file.match(match)) .forEach(file => { const filePath = join(dir, file); const newFilePath = join(dir, file.replace(match, replace)); renameSync(filePath, newFilePath); }); // Usage -
scriptex revised this gist
Mar 13, 2019 . 1 changed file with 1 addition and 3 deletions.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 @@ -7,9 +7,7 @@ const replace = args[2]; const files = fs.readdirSync(dir); files .filter(file => file.match(match)) .forEach(file => { const filePath = path.join(dir, file); const newFilePath = path.join(dir, file.replace(match, replace)); -
scriptex created this gist
Nov 23, 2017 .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,21 @@ const fs = require('fs'); const path = require('path'); const args = process.argv.slice(2); const dir = args[0]; const match = RegExp(args[1], 'g'); const replace = args[2]; const files = fs.readdirSync(dir); files .filter(file => { return file.match(match); }) .forEach(file => { const filePath = path.join(dir, file); const newFilePath = path.join(dir, file.replace(match, replace)); fs.renameSync(filePath, newFilePath); }); // Usage // node rename.js path/to/directory 'string-to-search' 'string-to-replace'