Last active
March 9, 2017 08:09
-
-
Save JacksonTian/953dd11ab805bec504b1867d9e61368b to your computer and use it in GitHub Desktop.
批量替换文件名
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 characters
'use strict'; | |
const fs = require('fs'); | |
const path = require('path'); | |
const mkdirp = require('mkdirp'); | |
const files = fs.readdirSync(__dirname); | |
files.forEach((filename) => { | |
if (filename.includes('\\')) { | |
var parts = filename.split('\\'); | |
var newPath = path.join(__dirname, ...parts); | |
var dirname = path.dirname(newPath); | |
console.log(newPath); | |
mkdirp.sync(dirname); | |
var oldPath = path.join(__dirname, filename); | |
fs.renameSync(oldPath, newPath); | |
} | |
}); | |
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 characters
'use strict'; | |
const fs = require('fs'); | |
const path = require('path'); | |
const replaced = 'Theme-LightWayAdmin\\'; | |
const files = fs.readdirSync(__dirname); | |
files.forEach((filename) => { | |
if (filename.startsWith(replaced)) { | |
var oldPath = path.join(__dirname, filename); | |
var newPath = path.join(__dirname, filename.substr(replaced.length)); | |
fs.renameSync(oldPath, newPath); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment