Make Directories
Path:
/src/method/mkdirs.coffeecompiled to/lib/method/mkdirs.js
The basicfs.mkdir() will only create one directory. While this extension gives additional methods (in plural) which will also create the full path if possible.
With the maxnum parameter you can control the maximum number of directories to create.
So if more are neccessary it will given an Error and won’t create something for
this task.
If an EEXIST code will be thrown internally this signals that the directory is already
there so this methods will succeed without doing anything and without Error. All
other errors will be given back.
Example Use
CoffeeScript Code fs = require 'alinex-fs'
fs.mkdirs '/tmp/some/directory', (err, made) ->
return console.error err if err
if made
console.log "Directory starting from #{made} was created."
console.log 'Directory now exists!'
Exported Methods
mkdirs()
Usage:
mkdirs(dir, mode, maxnum, cb)
- Parameter
-
dir-Stringdirectory path to createmode-String|Integeroptional the permission mode for the directories (may be given as string like ‘775’)maxnum-Integeroptional the maximum number of directories to createcb-function(<Error>, <Integer>)optional callback method given the path of the first directory which was created ornullif nothing had to be done. The errors may be:ENOENTNot allowed to create as many directories: …- and others
mkdirsSync()
Usage:
mkdirsSync(dir, mode, maxnum)
- Parameter
-
dir-Stringdirectory path to createmode-String|Integeroptional the permission mode for the directories (may be given as string like ‘775’)maxnum-Integeroptional the maximum number of directories to create
- Return
Stringthe path of the first directory which was created ornullif nothing had to be done- Throws
-
Errorif anything out of order happened with the messagesENOENTNot allowed to create as many directories: …- and others
Debugging
Debugging is possible using environment setting:
DEBUG=fs:mkdirs
fs:mkdirs directory /home/alex/github/node-fs/test/temp/with/multiple/dirs? +0ms
fs:mkdirs -> parent is missing +1ms
fs:mkdirs directory /home/alex/github/node-fs/test/temp/with/multiple? +1ms
fs:mkdirs -> parent is missing +0ms
fs:mkdirs directory /home/alex/github/node-fs/test/temp/with? +0ms
fs:mkdirs -> parent is missing +0ms
fs:mkdirs directory /home/alex/github/node-fs/test/temp? +0ms
fs:mkdirs directory /home/alex/github/node-fs/test/temp created +0ms
fs:mkdirs directory /home/alex/github/node-fs/test/temp/with created +29ms
fs:mkdirs directory /home/alex/github/node-fs/test/temp/with/multiple created +0ms
fs:mkdirs directory /home/alex/github/node-fs/test/temp/with/multiple/dirs created +0ms