1.0.5 • Published 10 years ago

forcepaths v1.0.5

Weekly downloads
17
License
-
Repository
github
Last release
10 years ago

forcepaths

Create folders and files even if parent folders don't exist (node js)

Create a folder

var forcePaths = require('forcePaths');

forcePaths(
    "./my/long/path/to/a/folder",
    function(err,stat){
        if (!err) {
		     if (stat.isDirectory()) {
				// this test is only needed if you
				// want to verify that the path was not 
				// previously a file.
		     }
		  }
    }
);

Create a file

var forcePaths = require('forcePaths');

forcePaths(
    "./my/long/path/to/a/file/hello.txt",
    "hello world",// <<< write this text to the file
    function(err,stat){
       if (err) {
          console.log(err);
       } 
    }
);

$R$ syntax (from requireasync)

eval(require('requireasync').install)

$R$({forcepaths:0})("./my/path/to/afile.txt","write this there");

Power user syntax

eval(require('requireasync').install)

$R$({

	forcepaths:function(f){

		f("./my/path/to/afile.txt","write this there");
		f("./my/path/to/folder");
		f("./my/path/to/anotherfile","write this there");
		f("./my/path/to/folder/subfolder",function(err,stat){ console.log(err?err:stat?stat.mtime:"wtf happened?");});

	}

})    

    
1.0.5

10 years ago

1.0.4

10 years ago

1.0.3

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago