繁体   English   中英

用我选择的一个替换父目录名称

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM