}
});
+### fs.exists(p, [callback])
+
+Test whether or not the given path exists by checking with the file system.
+Then call the `callback` argument with either true or false. Example:
+
+ fs.exists('/etc/passwd', function (exists) {
+ util.debug(exists ? "it's there" : "no passwd!");
+ });
+
+
+### fs.existsSync(p)
+
+Synchronous version of `fs.exists`.
+
## fs.Stats
Objects returned from `fs.stat()`, `fs.lstat()` and `fs.fstat()` and their
paths. Almost all these methods perform only string transformations.
The file system is not consulted to check whether paths are valid.
-`path.exists` and `path.existsSync` are the exceptions, and should
-logically be found in the fs module as they do access the file system.
-
Use `require('path')` to use this module. The following methods are provided:
### path.normalize(p)
// returns
''
-### path.exists(p, [callback])
-
-Test whether or not the given path exists by checking with the file system.
-Then call the `callback` argument with either true or false. Example:
-
- path.exists('/etc/passwd', function (exists) {
- util.debug(exists ? "it's there" : "no passwd!");
- });
-
-
-### path.existsSync(p)
-
-Synchronous version of `path.exists`.
return this._checkModeProperty(constants.S_IFSOCK);
};
+fs.exists = function(path, callback) {
+ binding.stat(path, function(err, stats) {
+ if (callback) callback(err ? false : true);
+ });
+};
+
+fs.existsSync = function(path) {
+ try {
+ binding.stat(path);
+ return true;
+ } catch (e) {
+ return false;
+ }
+};
+
fs.readFile = function(path, encoding_) {
var encoding = typeof(encoding_) === 'string' ? encoding_ : null;
var callback = arguments[arguments.length - 1];
var isWindows = process.platform === 'win32';
+var _deprecationWarning = require('util')._deprecationWarning;
// resolves . and .. elements in a path array with directory names there
exports.exists = function(path, callback) {
- process.binding('fs').stat(path, function(err, stats) {
- if (callback) callback(err ? false : true);
- });
+ _deprecationWarning('path', '`path.exists` is now called `fs.exists`');
+ require('fs').exists(path, callback);
};
exports.existsSync = function(path) {
- try {
- process.binding('fs').stat(path);
- return true;
- } catch (e) {
- return false;
- }
+ _deprecationWarning('path', '`path.exists` is now called `fs.exists`');
+ return require('fs').existsSync(path);
};
--- /dev/null
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+var assert = require('assert');
+var fs = require('fs');
+var f = __filename;
+var exists;
+var doesNotExist;
+
+fs.exists(f, function(y) {
+ exists = y;
+});
+
+fs.exists(f + '-NO', function (y) {
+ doesNotExist = y;
+});
+
+assert(fs.existsSync(f));
+assert(!fs.existsSync(f + '-NO'));
+
+process.on('exit', function () {
+ assert.strictEqual(exists, true);
+ assert.strictEqual(doesNotExist, false);
+});
var common = require('../common');
var assert = require('assert');
-var path = require('path');
var fs = require('fs');
function unlink(pathname) {
fs.mkdir(pathname, function(err) {
assert.equal(err, null);
- assert.equal(path.existsSync(pathname), true);
+ assert.equal(fs.existsSync(pathname), true);
ncalls++;
});
fs.mkdir(pathname, 511 /*=0777*/, function(err) {
assert.equal(err, null);
- assert.equal(path.existsSync(pathname), true);
+ assert.equal(fs.existsSync(pathname), true);
ncalls++;
});
unlink(pathname);
fs.mkdirSync(pathname);
- var exists = path.existsSync(pathname);
+ var exists = fs.existsSync(pathname);
unlink(pathname);
assert.equal(exists, true);
'\\\\unc\\share\\foo\\bar');
}
-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'), '');