Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>make a synchronous version base on geoffreak's.</p> <p>thanks for geoffreak.</p> <pre><code>function mkdirs(path, mode, callback){ var path = path.indexOf('\\') &gt;= 0 ? path.replace(/\\/g, '/') : path;//change windows slashes to unix if (path.substr(path.length - 1) == '/') { //remove trailing slash path = path.substr(0, path.length - 1); } console.log('path is:' + path ); function tryDirectory(dir, cb){ console.log('path is:' + dir ); var stat ; try { stat = fs.statSync(dir) ; // the file exist if (stat.isDirectory()) { //directory exists, no need to check previous directories cb(); } else { //file exists at location, cannot make folder return cb(new Error('exists')); } } catch(err) { if (err) { //the file doesn't exist, try one stage earlier then create console.log('failed to get stat of ' + dir + ', errno is :' + err.errno); if (err.errno == 2 || err.errno == 32 || err.errno == 34 ) { //if (dir.lastIndexOf('/') == dir.indexOf('/')) {//only slash remaining is initial slash //should only be triggered when path is '/' in Unix, or 'C:/' in Windows //cb(new Error('notfound')); //} if (dir.length &lt; 2) { cb(new Error('invalid_path')); } else { // try one stage earlier then create tryDirectory(dir.substr(0, dir.lastIndexOf('/')), function(err){ if (err) { //error, return cb(err); } else { //make this directory try { fs.mkdirSync(dir, mode); console.log('make dir ok, dir:' + dir); cb(); } catch (error) { if (error &amp;&amp; error.errno != 17 ) { console.log("Failed to make " + dir); return cb(new Error('failed')); } } } }); } } else { //unkown error console.log(util.inspect(err, true)); cb(err); } } } } tryDirectory(path, callback); }; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload