【发布时间】:2021-06-10 02:14:53
【问题描述】:
我想获取 20000 个文件的创建日期并将其存储在一个数组中。
完成的总时间是 35 分钟,相当长的时间。 (Image Processing Time)
有没有办法以更快的处理时间创建数组?
获取如下文件创建日期数组的当前逻辑是否有任何问题?
① 数组声明:var arr = [];
② 我使用下面的代码来获取文件创建日期:
var fs = global.get('fs');
// Get file creation date time
msg.createdDate = fs.statSync(msg.pathFName).birthtime;
return msg;
③ 将创建日期存储在一个数组中。
我的流量:
Image Flow
[
{
"id": "de157360.11d49",
"type": "tab",
"label": "フロー 1",
"disabled": false,
"info": ""
},
{
"id": "6a8db36.f55e14c",
"type": "inject",
"z": "de157360.11d49",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "str",
"x": 750,
"y": 160,
"wires": [
[
"4907d69b.07f738"
]
]
},
{
"id": "4907d69b.07f738",
"type": "change",
"z": "de157360.11d49",
"name": "",
"rules": [
{
"t": "set",
"p": "pathFiles",
"pt": "msg",
"to": "D:\\Data\\",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 910,
"y": 160,
"wires": [
[
"d68da128.cd6d9"
]
]
},
{
"id": "d68da128.cd6d9",
"type": "fs-ops-dir",
"z": "de157360.11d49",
"name": "",
"path": "pathFiles",
"pathType": "msg",
"filter": "*",
"filterType": "str",
"dir": "files",
"dirType": "msg",
"x": 1080,
"y": 160,
"wires": [
[
"764296f2.688338"
]
]
},
{
"id": "764296f2.688338",
"type": "change",
"z": "de157360.11d49",
"name": "f=0",
"rules": [
{
"t": "set",
"p": "f",
"pt": "msg",
"to": "0",
"tot": "num"
},
{
"t": "set",
"p": "arrObjFiles",
"pt": "msg",
"to": "[]",
"tot": "json"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 1210,
"y": 160,
"wires": [
[
"ab664988.c25da8",
"232fdda0.b11e22"
]
]
},
{
"id": "1912092c.fbab77",
"type": "change",
"z": "de157360.11d49",
"name": "f++",
"rules": [
{
"t": "set",
"p": "f",
"pt": "msg",
"to": "$.f + 1\t",
"tot": "jsonata"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 1650,
"y": 60,
"wires": [
[
"ab664988.c25da8"
]
]
},
{
"id": "ab664988.c25da8",
"type": "switch",
"z": "de157360.11d49",
"name": "u<number of files",
"property": "f",
"propertyType": "msg",
"rules": [
{
"t": "lt",
"v": "files.length",
"vt": "msg"
},
{
"t": "else"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 1410,
"y": 160,
"wires": [
[
"15154524.a6828b"
],
[
"c7625457.8ccb18"
]
]
},
{
"id": "f8030294.f6334",
"type": "function",
"z": "de157360.11d49",
"name": "Get file creation date time",
"func": "var fs = global.get('fs');\n// Get file creation date time\nmsg.createdDate = fs.statSync(msg.pathFName).birthtime;\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"x": 1830,
"y": 160,
"wires": [
[
"59879c16.6c7564"
]
]
},
{
"id": "59879c16.6c7564",
"type": "change",
"z": "de157360.11d49",
"name": "Storage file creation date time",
"rules": [
{
"t": "set",
"p": "objFiles",
"pt": "msg",
"to": "{}",
"tot": "json"
},
{
"t": "set",
"p": "objFiles",
"pt": "msg",
"to": "$merge([$.objFiles,{'fileName': $.fileName,'createdDate': $.createdDate}])",
"tot": "jsonata"
},
{
"t": "set",
"p": "arrObjFiles",
"pt": "msg",
"to": "$append(arrObjFiles, [objFiles])",
"tot": "jsonata"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 2090,
"y": 160,
"wires": [
[
"1912092c.fbab77"
]
]
},
{
"id": "15154524.a6828b",
"type": "change",
"z": "de157360.11d49",
"name": "",
"rules": [
{
"t": "set",
"p": "fileName",
"pt": "msg",
"to": "$.files[$$.f]",
"tot": "jsonata"
},
{
"t": "set",
"p": "pathFName",
"pt": "msg",
"to": "pathFiles & fileName",
"tot": "jsonata"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 1620,
"y": 160,
"wires": [
[
"f8030294.f6334"
]
]
},
{
"id": "c7625457.8ccb18",
"type": "debug",
"z": "de157360.11d49",
"name": "END",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "arrObjFiles",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 1590,
"y": 220,
"wires": []
},
{
"id": "232fdda0.b11e22",
"type": "debug",
"z": "de157360.11d49",
"name": "START",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "files.length",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 1380,
"y": 220,
"wires": []
}
]
【问题讨论】:
标签: javascript node.js node-red