How to use the statSync function from graceful-fs

Find comprehensive JavaScript graceful-fs.statSync code examples handpicked from public code repositorys.

18
19
20
21
22
23
24
25
26
27
/**
 * Returns true if the path exists and is a directory, false otherwise.
 */
function directoryExistsSync(path) {
  try {
    var stats = fs.statSync(path);
    return stats.isDirectory();
  } catch (e) {
    if (e.code === 'ENOENT')
      return false;
fork icon291
star icon672
watch icon0

519
520
521
522
523
524
525
526
527
528
529
exports.rmdir = rmdir;
exports.rmdirSync = rmdirSync;


// stat
exports.stat = Promise.promisify(fs.stat);
exports.statSync = fs.statSync;
exports.fstat = Promise.promisify(fs.fstat);
exports.fstatSync = fs.fstatSync;
exports.lstat = Promise.promisify(fs.lstat);
exports.lstatSync = fs.lstatSync;
fork icon9
star icon48
watch icon0

+ 7 other calls in file

206
207
208
209
210
211
212
213
214
215
return fs.readdirSync(path)
  .filter(ignoreHiddenFiles(options.ignoreHidden == null ? true : options.ignoreHidden))
  .filter(ignoreFilesRegex(options.ignorePattern))
  .map(item => {
    const fullPath = join(path, item);
    const stats = fs.statSync(fullPath);

    return {
      isDirectory: stats.isDirectory(),
      path: item,
fork icon0
star icon1
watch icon0

+ 23 other calls in file

12
13
14
15
16
17
18
19
20
21
22
  const d = new Date(1435410243862)
  fs.writeFileSync(tmpfile, 'https://github.com/jprichardson/node-fs-extra/pull/141')
  const fd = fs.openSync(tmpfile, 'r+')
  fs.futimesSync(fd, d, d)
  fs.closeSync(fd)
  return fs.statSync(tmpfile).mtime > 1435410243000
}


function hasMillisRes (callback) {
  let tmpfile = path.join('millis-test' + Date.now().toString() + Math.random().toString().slice(2))
fork icon1
star icon0
watch icon0

47
48
49
50
51
52
53
54
55
56
57
58
    }
  }
}


function moveSyncAcrossDevice (src, dest, overwrite) {
  const stat = fs.statSync(src)


  if (stat.isDirectory()) {
    return moveDirSyncAcrossDevice(src, dest, overwrite)
  } else {
fork icon0
star icon1
watch icon0

9
10
11
12
13
14
15
16
17
18
19
const createLazyTestEnv = require("./helpers/createLazyTestEnv");


const casesPath = path.join(__dirname, "hotCases");
let categories = fs
	.readdirSync(casesPath)
	.filter(dir => fs.statSync(path.join(casesPath, dir)).isDirectory());
categories = categories.map(cat => {
	return {
		name: cat,
		tests: fs
fork icon163
star icon0
watch icon24

+ 13 other calls in file

16
17
18
19
20
21
22
23
24
25
if (!fs.existsSync(dest)) fs.mkdirSync(dest);
const files = fs.readdirSync(src);
files.forEach(filename => {
	const srcFile = path.join(src, filename);
	const destFile = path.join(dest, filename);
	const directory = fs.statSync(srcFile).isDirectory();
	if (directory) {
		copyDiff(srcFile, destFile, initial);
	} else {
		var content = fs.readFileSync(srcFile);
fork icon163
star icon0
watch icon24

+ 13 other calls in file

93
94
95
96
97
98
99
100
101
102
const testDirectory = path.join(casesPath, category.name, testName);
const runs = fs
	.readdirSync(testDirectory)
	.sort()
	.filter(name => {
		return fs.statSync(path.join(testDirectory, name)).isDirectory();
	})
	.map(name => ({ name }));

beforeAll(done => {
fork icon0
star icon0
watch icon1

+ 15 other calls in file

255
256
257
258
259
260
261
262
263
264
if (!active) {
  return Promise.resolve();
}

try {
  fs.statSync(cacheAssetDirPath);
} catch (_) {
  mkdirp.sync(cacheAssetDirPath);
  logMessages.configHashFirstBuild(compiler, {
    cacheDirPath,
fork icon0
star icon0
watch icon1

+ 30 other calls in file

188
189
190
191
192
193
194
195
196
197

if (!options.mode || !options.chown) {
  // Either mode or chown is not explicitly set
  // Default behavior is to copy it from original file
  try {
    var stats = fs.statSync(filename)
    options = Object.assign({}, options)
    if (!options.mode) {
      options.mode = stats.mode
    }
fork icon0
star icon0
watch icon0

+ 3 other calls in file

74
75
76
77
78
79
80
81
82
83
84
	}
};


exports.statSync = path => {
	try {
		return fs.statSync(path);
	} catch (error) {
		throw new CpFileError(`stat \`${path}\` failed: ${error.message}`, error);
	}
};
fork icon0
star icon0
watch icon0