Skip to content

Commit

Permalink
批量修改文件名
Browse files Browse the repository at this point in the history
  • Loading branch information
baichun committed May 6, 2019
1 parent 10f9f95 commit 184eec7
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ src
|
└───util(工具函数)
|
└───deepClone(深拷贝)
└───deepClone(深拷贝)
|
└───renameFile(批量修改文件名)
8 changes: 7 additions & 1 deletion src/algorithm/quickSort.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { deepClone } from "@/util/deepClone.js";

let demoArr = [1, 9, 5, 6, 2, 8, 7]; //实例数组

/**
* 快速排序
* 原理:
* 原理: 以一个数位基准
* 先从一边找出一个大于/小于基准的数
* 再从另一边找出小于/大于基准的数,交换他们
*/

export function quickSort(){
Expand Down
33 changes: 33 additions & 0 deletions src/util/renameFile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
var fs = require('fs');

var PATH = './src/components/listNav/img'; // 目录

// 遍历目录得到文件信息
function walk(path, callback) {
var files = fs.readdirSync(path);

files.forEach(function(file){
if (fs.statSync(path + '/' + file).isFile()) {
callback(path, file);
}
});
}

// 修改文件名称
function rename (oldPath, newPath) {
fs.rename(oldPath, newPath, function(err) {
if (err) {
throw err;
}
});
}

// 运行
walk(PATH, function (path, fileName) {
var oldPath = path + '/' + fileName, // 源文件路径
newPath = path + '/'+ fileName.replace(/icon-/, 'icon_'); // 新路径

rename(oldPath, newPath);
});

//copy: https://www.jianshu.com/p/4d823a522ccc
Empty file added src/vue/vdom.html
Empty file.

0 comments on commit 184eec7

Please sign in to comment.