nanhupatar / dress Goto Github PK
View Code? Open in Web Editor NEW好耶是女装小程序
好耶是女装小程序
const fs = require("fs");
const path = require("path");
const whiteList = [".git"];
const config = {
env: "test-f726fb",
storage: "7465-test-f726fb",
dir: "dress/"
};
//解析需要遍历的文件夹,我这以E盘根目录为例
//调用文件遍历方法
init();
function init() {
let filePath = path.resolve("D:/Dress");
let list = [];
let files = fs.readdirSync(filePath);
files.forEach(function(filename, index) {
let fullname = path.join(filePath, filename);
let stats = fs.statSync(fullname);
if (stats.isDirectory() && !whiteList.includes(filename)) {
let dressInfo = {
userInfo: {
nickName: filename,
avatarUrl: ""
},
images: [],
dressFlag: 1,
description: "",
star: 0,
share: 0,
tags: [],
createTime: new Date().getTime()
};
list[index] = dressInfo;
getFile(fullname, filename, list[index].images);
}
});
list.forEach((item, index) => {
let dressInfo = JSON.stringify(item) + "\r\n\r\n";
fs.writeFile("dress.json", dressInfo, { flag: "a" }, err => {
if (err) throw err;
// console.log("saved," + dressInfo);
});
});
}
function getFile(filePath, nickName, images) {
let files = fs.readdirSync(filePath);
files.forEach((filename, index) => {
let fullname = path.join(filePath, filename);
let stats = fs.statSync(fullname);
if (stats.isFile() && isImage(filename)) {
let name = generateName(nickName, filename);
images.push(name);
}
if (stats.isDirectory() && !whiteList.includes(filename)) {
getFile(fullname, nickName, images);
}
});
}
function isImage(filename) {
return /\.(png|jpe?g|gif|svg)(\?.*)?$/.test(filename);
}
function generateName(nickName, filename) {
// cloud://test-f726fb.7465-test-f726fb/dress/60heye/IMG_3385.jpg
return "cloud://" + config.env + "." + config.storage + "/" + config.dir + nickName + "/" + filename;
}
var fs = require("fs");
var path = require("path");
//解析需要遍历的文件夹,我这以E盘根目录为例
var filePath = path.resolve("D:/Dress");
//调用文件遍历方法
fileDisplay(filePath);
/**
* 文件遍历方法
* @param filePath 需要遍历的文件路径
*/
function fileDisplay(filePath) {
//根据文件路径读取文件,返回文件列表
fs.readdir(filePath, function(err, files) {
if (err) {
console.warn(err);
} else {
//遍历读取到的文件列表
files.forEach(function(filename) {
//获取当前文件的绝对路径
var filedir = path.join(filePath, filename);
//根据文件路径获取文件信息,返回一个fs.Stats对象
fs.stat(filedir, function(eror, stats) {
if (eror) {
console.warn("获取文件stats失败");
} else {
var isFile = stats.isFile(); //是文件
var isDir = stats.isDirectory(); //是文件夹
if (isFile) {
console.log(filename);
let obj = JSON.stringify({ filename: filename });
obj += "\n";
fs.writeFile(
"input.json",
obj,
{
flag: "a"
},
function(err) {
if (err) {
return console.error(err);
}
// fs.readFile("input.txt", function(err, data) {
// if (err) {
// return console.error(err);
// }
// // console.log("异步读取文件数据: " + data.toString());
// });
}
);
}
if (isDir) {
fileDisplay(filedir); //递归,如果是文件夹,就继续遍历该文件夹下面的文件
}
}
});
});
}
});
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.