Search code examples
directoryphantomjscasperjs

create directory (tree) phantomjs casperjs not working


I'm working on windows 10 X64

using casperjs and phantomjs

CasperJS version 1.1.2 at C:/casperjs, using phantomjs version 2.1.1

try to create multi dir with it but no luck, the only work is create 1 dir only

from document

http://phantomjs.org/api/fs/method/make-tree.html

var fs = require('fs');
var path = 'D:\\test2\\2ss\\hhh\\gu';
if(fs.makeDirectory(path))
console.log('"'+path+'" was created.');
else
console.log('"'+path+'" is NOT created.');
phantom.exit();

result (path changed)

D:\work>casperjs dir.js
"D:\test\1\1\2" is NOT created.

D:\work>casperjs dir.js
"D:\test2" was created.  // this work when make 1 dir only

D:\work>casperjs dir.js
"D:\test3\2dd" is NOT created.

D:\work>casperjs dir.js
"D:\test2\2ss" was created. . // Working because test2 was created before

D:\work>casperjs dir.js
"D:\test2\2ss\hhh\gu" is NOT created.

Solution

  • Change makedirectory to maketree. It will work!

    var fs = require('fs');
    var path = 'D:\\test2\\2ss\\hhh\\gu';
    if(fs.makeTree(path))
    console.log('"'+path+'" was created.');
    else
    console.log('"'+path+'" is NOT created.');
    phantom.exit();
    

    the result

    D:\work>casperjs dir.js
    "D:\test2\2ss\hhh\gu" was created.