Permalink
Browse files

added rename

  • Loading branch information...
1 parent 41ad33c commit dcca394278fb7d4fd98099eb04aa6955806ea38c @tommy351 committed Sep 3, 2012
Showing with 38 additions and 2 deletions.
  1. +38 −2 lib/qfs.js
View
40 lib/qfs.js
@@ -334,10 +334,31 @@ utils.each({
],
rename: [
function(name, callback){
+ var arr = [],
+ fn = [];
+
+ this.each(function(){
+ var _this = this;
+ fn.push(function(next){
+ fs.rename(_this.dir() + sep + name, next);
+ });
+ });
+
+ async.parallel(fn, callback.bind(qfs(arr)));
+
+ return this;
},
function(name){
+ var arr = [];
+
+ this.each(function(){
+ var path = this.dir() + sep + name;
+ fs.renameSync(path);
+ arr.push(path);
+ });
+ return qfs(arr);
}
],
remove: [
@@ -347,7 +368,16 @@ utils.each({
this.each(function(){
var path = this.path();
fn.push(function(next){
- fn.unlink(path, next);
+ this.stat(function(err, stat){
+ if (err) return callback(err);
+ if (stat.isFile()){
+ fs.unlink(path, next);
+ } else {
+ this.empty(function(){
+ fs.rmdir(path, next);
+ });
+ }
+ });
});
});
@@ -357,7 +387,13 @@ utils.each({
},
function(){
this.each(function(){
- fs.unlinkSync(this.path());
+ var stat = this.stat();
+ if (stat.isFile()){
+ fs.unlinkSync(this.path());
+ } else {
+ this.empty();
+ fs.rmdirSync(this.path());
+ }
});
return this;

0 comments on commit dcca394

Please sign in to comment.