|
- "use strict";
- var fs = require('fs');
- var args = process.argv.splice(2);
- var fileDirectory = args[0];
- var type = args[1];//哪个后缀 .png 输入 png
- var ownStr = args[2];//包含的字符串 比如:acti147
- var replaceStr = args[3];//要替换的字符串 比如:acti155 把png后缀的acti147替换为acti155
- if (fs.existsSync(fileDirectory)) {
- var files = fs.readdirSync(fileDirectory);
- files.forEach(function (file) {
- var filePath = fileDirectory + "/" + file;
- var preFixFile = file.split(".")[0];
- var suffFixFile = file.split(".")[1];
- if (type == suffFixFile && preFixFile.indexOf(ownStr) > -1) {
- console.log("filePathfilePath:" + filePath);
- console.log("file:" + file);
- var newPreFixFile = preFixFile.replace(ownStr, replaceStr);
- var newFileName = newPreFixFile + "." + suffFixFile;
- var newFilePath = fileDirectory + "/" + newFileName;
- fs.rename(filePath, newFilePath, function (err) {
- if (err) throw err;
- console.log(newFileName + ' ~convert ok~');
- });
- }
- });
- } else {
- console.log(fileDirectory + " Not Found!");
- }
复制代码 |
|