[英]Replace parent directory name with one of my choice
我正在嘗試用我選擇的名稱替換路徑的父文件夾。
exports.uploadDirectory = async function(dir, customer) {
var fullPathArray = [];
var params = [];
// Read all folders, subfolder and files and add them to an array
fs.readdirSync(dir).forEach(file => {
let fullPath = path.join(dir, file);
if (fs.lstatSync(fullPath).isDirectory()) {
exports.uploadDirectory(fullPath);
} else {
fullPathArray.push(fullPath);
}
});
// Loop through each file found and add it to the object params array
fullPathArray.forEach(function(value){
let init_value = value.split(/\/(.+)/)[1]; // Removing old parent folder
console.log(customer + '/' + init_value); // Thought this may work but returns the below
params.push({ Bucket: config.S3.bucket, Key: init_value, Body: fs.createReadStream(value) });
});
// More Stuff here
};
控制台日志打印
undefined/New Folder 2/test22.js
myCustomer/index.html
myCustomer/test.js
如您所見,具有子目錄的第一項返回未定義。 但是父目錄中的文件工作正常。
預期的
myCustomer/New Folder 2/test22.js
myCustomer/index.html
myCustomer/test.js
編輯
價值是;
New Folder/New Folder 2/test22.js
New Folder/index.html
New Folder/test.js
init_value 是;
New Folder 2/test22.js
index.html
test.js
稱呼
exports.handler = async (event) => {
await content.uploadDirectory("./New Folder", "myCustomer");
};
看來問題出在這里
exports.uploadDirectory(fullPath)
你忘記給客戶打電話了,應該是
exports.uploadDirectory(fullPath, customer)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.