0

I want to copy a file and change the directory of that file

Here is my file location:

Test.zip -> Account/Images/
                   -account.png
                   -icon.png
                   -flag.png
                    .
                    .

When I use the script for extracting the files I want to have, just account.png file outside of Images folder :

Account/
     - account.png
     - Images/ icon.png,flag.png

Here is my function

function processFiles(fileDir, outputDir, accountData) {

var fileDensities;
fileDensities.forEach(function(density) {
    var srcPath = path.join(fileDir, 'Account', output);
    if (!fs.existsSync(srcPath)) {
        console.log('Warning: image does not exist' + output);
        return;
    };
    var outputPath = path.join(outputDir, output);
    mkdirp.sync(outputPath);
    var srcFilenames = fs.readdirSync(srcPath);
    srcFilenames.forEach(function(filename) {

  });
 }

Right-now the output is :

    Account/Images/account.png,icon.png,flag.png

My question is how can I add account.png outside of Images folder

Account/
     - account.png
     - Images/ icon.png,flag.png

Thanks in Advance!

0

1 Answer 1

1

In srcFilenames.forEach(function(filename) {, check if the filename is account.png and then change the outputPath so that it doesn't contain the last part Images/.

You could avoid comparing with all of the filenames by removing the account.png file from the srcFilenames array and handling it separately.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.