Created
May 4, 2018 22:14
-
-
Save ducngtuan/c9c79a3fc259f8e6f785ffced6fe2490 to your computer and use it in GitHub Desktop.
Script to rename files based on regex pattern in javascript
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 fs = require('fs'), | |
path = require('path'), | |
dir = '~/Downloads', | |
match = /.*_(\w+\.part\d+.rar)/ // change this to whatever pattern needed | |
files = fs.readdirSync(dir) | |
files.filter(f => f.match(match)).forEach(f => { | |
const fpath = path.join(dir, f), | |
newfpath = path.join(dir, f.replace(match, (m, p1) => p1)) | |
fs.renameSync(fpath, newfpath) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment