Permalink
Browse files

Adding path.existsSync (with tests.)

  • Loading branch information...
1 parent 73f207f commit b05daaaf69c5445dd28ad3efab118ce92cd23afb @miksago miksago committed with ry Jun 16, 2010
Showing with 11 additions and 0 deletions.
  1. +9 −0 lib/path.js
  2. +2 −0 test/simple/test-path.js
View
@@ -79,3 +79,12 @@ exports.exists = function (path, callback) {
if (callback) callback(err ? false : true);
});
};
+
+exports.existsSync = function (path) {
+ try {
+ process.binding('fs').stat(path)
+ return true;
+ } catch(e){
+ return false;
+ }
+};
@@ -12,6 +12,8 @@ assert.equal(path.dirname("/a"), "/");
assert.equal(path.dirname("/"), "/");
path.exists(f, function (y) { assert.equal(y, true) });
+assert.equal(path.existsSync(f), true);
+
assert.equal(path.extname(""), "");
assert.equal(path.extname("/path/to/file"), "");
assert.equal(path.extname("/path/to/file.ext"), ".ext");

0 comments on commit b05daaa

Please sign in to comment.