asyncfunctionmain(path) { // Use connect method to connect to the server await client.connect(); console.log('Connected successfully to server'); const db = client.db(dbName); const collection = db.collection('file');
path = path.replace(/\\/g, '/') console.log(path)
// 分割路径 + 文件名 functiongetDirName(path) { var arr = path.split("/") var filename = arr[arr.length -1] var fileDir = ""; for (let i = 0; i < arr.length-1; i++) { fileDir += arr[i] + "/" } return [fileDir,filename] } [fileDir,filename] = getDirName(path); // 获取文件大小 functiongetSize(path) { var size; var fileMsg = fs.statSync(path); if(fileMsg.size < 1024) size = fileMsg.size + 'b' elseif(fileMsg.size < 1024 * 1024) size = (fileMsg.size/1024).toFixed(2) + 'kb' elseif(fileMsg.size < 1024 * 1024 * 1024) size = (fileMsg.size/1024/1024).toFixed(2) + 'MB' return size; } var size = getSize(path)