-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfindSortRename.js
More file actions
54 lines (51 loc) · 1.55 KB
/
Copy pathfindSortRename.js
File metadata and controls
54 lines (51 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// 遍历查找重命名写真图片
const fs = require("fs");
const path = require("path");
const imagesizeof = require("image-size");
function travel(dir, callback) {
fs.readdirSync(dir).forEach(function (file) {
let pathname = path.join(dir, file);
if (fs.statSync(pathname).isDirectory()) {
travel(pathname, callback);
} else {
if (file.indexOf("jpg") > -1 && file !== "cover.jpg") {
callback(pathname);
}
}
});
}
function PrefixZero(num, n) {
return (Array(n).join(0) + num).slice(-n);
}
function copyAndPaste(sourcePath, targetPath, imageCount) {
let targetFullPath = `${targetPath}/${imageCount}.jpg`;
fs.copyFile(sourcePath, targetFullPath, (err) => {
if (err) console.log(err);
});
console.log(`${sourcePath} ====> ${targetFullPath}`);
}
// 杨晨晨高清图片最后一张序号
// width:2980
// height:13774
// 绯月樱高清图片最后一张序号
// width:457
// height:2436
let widthCount = 912;
let heightCount = 7512;
let basePath = "E:/image";
let modelName = "绯月樱";
let sourceBasePath = `${basePath}/${modelName}临时`;
let targetBasePath = `${basePath}/${modelName}`;
travel(sourceBasePath, function (pathname) {
let imageInfo = imagesizeof(pathname);
let imageCount;
let targetPath;
if (imageInfo.width > imageInfo.height) {
imageCount = PrefixZero(++widthCount, 5);
targetPath = targetBasePath + "/width_bg";
} else {
imageCount = PrefixZero(++heightCount, 5);
targetPath = targetBasePath + "/height_bg";
}
copyAndPaste(pathname, targetPath, imageCount);
});