Skip to content

Is there a better way to create multiple directories using mkdir? #26993

Description

@FlandersBurger

is there a better way to create a folder structure than nesting mkdirs?


          var dir = 'companies/' + newCompany.number;
          fs.mkdir(dir, function(err) {
            if (err) console.error(err);
            fs.mkdir(dir + '/pdfs', function(err) {
              if (err) console.error(err);
              fs.mkdir(dir + '/fonts', function(err) {
                if (err) console.error(err);
                fs.mkdir(dir + '/users', function(err) {
                  if (err) console.error(err);
                });
              });
            });
          });

Activity

  1. sam-github commented on Mar 29, 2019

    @sam-github
    Contributor

    Please post general questions on using node to nodejs/help.

    There is a documented recursive option to mkdir: https://nodejs.org/api/fs.html#fs_fs_mkdir_path_options_callback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions