How to use the statSync function from fs-extra

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

527
528
529
530
531
532
533
534
535
var dirs = [];
try {        
       rootpath = path.normalize(rootpath || srcpath);
       fs.readdirSync(srcpath).forEach((file) => {
           var fullname = path.join(srcpath, file);
           var fstat = fs.statSync(fullname);
           if (fstat.isDirectory()) {

               var packName = fullname;
fork icon82
star icon94
watch icon26

+ 19 other calls in file

139
140
141
142
143
144
145
146
147
148

it('can write large documents', function(done) {
    partition.open();
    let blob = 'foobar'.repeat(100000);
    partition.write(blob, () => {
        let stat = fs.statSync('test/data/.part');
        expect(stat.size).to.be.greaterThan(blob.length);
        done();
    });
});
fork icon4
star icon31
watch icon0

+ 5 other calls in file

29
30
31
32
33
34
35
36
37
38
39
module.exports = function copyFileSync(source, output, options) {
    const stat = fs.statSync(source)


    if (options.update) {
        try {
            const dstStat = fs.statSync(output)
            if (dstStat.mtime.getTime() > stat.mtime.getTime()) {
                // Don't overwrite because the file on destination is newer than
                // the source file.
                return
fork icon3
star icon28
watch icon0

+ 3 other calls in file

8
9
10
11
12
13
14
15
16
17
18
let watch = false
let fast = false


function getMTime(path) {
    try {
        const st = fs.statSync(path)
        return st.mtimeMs
    } catch {
        return undefined
    }
fork icon4
star icon24
watch icon9

2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
  } else {
    isofile = true;
  }
} else {
  try {
    var stat = libFsExtra.statSync(uri);
  } catch (err) {
    self.logger.error("scanFolder - failure to stat '" + uri + "'");
    return uris;
  }
fork icon28
star icon21
watch icon4

5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
for (var i = 0; i < ev1.length; i++) {
  /// Get all the file information
  var itemPath = ev1[i].path;
  var itemName = path.parse(itemPath).base;
  var duplicate = false;
  var statsObj = fs.statSync(itemPath);
  // check for duplicate or files with the same name
  for (var j = 0; j < ev2.children.length; j++) {
    if (itemName === ev2.children[j].innerText) {
      duplicate = true;
fork icon9
star icon22
watch icon9

+ 69 other calls in file

542
543
544
545
546
547
548
549
550
551
// Collect some info regarding the MODDABLE toolkit

// https://stackoverflow.com/questions/18112204/get-all-directories-within-directory-nodejs
function getDirectories(parent_dir) {
    return fs.readdirSync(parent_dir).filter(function (file) {
        return fs.statSync(path.join(parent_dir,file)).isDirectory();
    });
  }

{
fork icon6
star icon21
watch icon3

+ 19 other calls in file

131
132
133
134
135
136
137
138
139
140
141
    }
}


function fileIsExists(filename){
    try{
        fs.statSync(filename)
        return true
    }catch(e){
        return false
    }
fork icon3
star icon24
watch icon3

453
454
455
456
457
458
459
460
461
462
    title: lang.main.ErrorLogoHdr,
    message: lang.main.ErrorLogoMultiMsg,
  });
  return;
}
const logoSize = fs.statSync(filteredPath[0]).size / 1000000.0;
if (logoSize > 10) {
  log.info(`App logo not valid due to file size being too large (${logoSize}MB)`);
  showErrorMsg({
    type: 'info',
fork icon1
star icon7
watch icon0

190
191
192
193
194
195
196
197
198
199
};
let getLocalFile = (dir, fn) => {
    let file = path.join(dir, fn);
    try {
        let packageFile = fs.readJsonSync(path.join(dir, "package.json"));
        fs.statSync(file.replace(/\.js$/, ".html"));
        return {
            path: dir,
            name: packageFile.name
        };
fork icon0
star icon2
watch icon0

+ 3 other calls in file

302
303
304
305
306
307
308
309
310
311
  return true
} else {
  var count = 0
  paths.forEach(function (p) {
    p = path.join(dirname, p)
    var stat = fs.statSync(p)
    if (stat.isDirectory()) {
      if (self.rmEmptyDirsSync(p)) {
        count++
      }
fork icon0
star icon2
watch icon0

7489
7490
7491
7492
7493
7494
7495
7496
7497
7498
7499
7500
}


function createFileSync (file) {
  let stats
  try {
    stats = fs.statSync(file)
  } catch (e) {}
  if (stats && stats.isFile()) return


  const dir = path.dirname(file)
fork icon0
star icon1
watch icon0

+ 35 other calls in file

178
179
180
181
182
183
184
185
186
187
  })
  .filter(function (path) {
    return (
      basename(path)[0] !== "-" &&
      basename(path)[0] !== "." &&
      fs.statSync(path).isDirectory()
    );
  });

callback(null, folders);
fork icon69
star icon0
watch icon23

+ 4 other calls in file

50
51
52
53
54
55
56
57
58
59
let cancelled;

try {
  size = prettySize(
    Math.round(
      fs.statSync(join(tempDir, "import", req.blog.id, i, "result.zip"))
        .size / 1000
    )
  );
} catch (e) {}
fork icon69
star icon0
watch icon23

+ 4 other calls in file

249
250
251
252
253
254
255
256
257
258
ran++;
log.sysLog(`Starting Nyx... {${ran}}`);
const i = await runProc();
log.sysLog(`Exited with code ${i}`);

const lastUpdated = fs.statSync(`./index.js`).mtimeMs;
if(lastUpdated > beginningUpdated) {
    log.sysWarn(`The index script has been updated ever since it was ran.`);
    log.sysLog(`Quitting host process to apply the update!`); process.exit(0)
};
fork icon1
star icon4
watch icon1

+ 5 other calls in file

188
189
190
191
192
193
194
195
196
197

// Remove theme dir
let themeDirStat = false;

try {
    themeDirStat = fs.statSync(path.join(this.sitePath, themeToRemove));
} catch(e) {}

if(themeDirStat && themeDirStat.isDirectory()) {
    // If yes - remove it
fork icon341
star icon0
watch icon79

+ 9 other calls in file

94
95
96
97
98
99
100
101
102
// Move images from the temp directory
let tempDirectoryExists = true;
let tempImagesDir = path.join(this.siteDir, 'input', 'media', 'tags', 'temp');

try {
    fs.statSync(tempImagesDir).isDirectory();
} catch (err) {
    tempDirectoryExists = false;
}
fork icon341
star icon0
watch icon79

+ 9 other calls in file

53
54
55
56
57
58
59
60
61
62
}

let files = fs.readdirSync(mods.path);
files.forEach((file) => {
	// return early if `file` isn't a folder
	if (! fs.statSync(path.join(mods.path, file)).isDirectory()) {
		return;
	}

	let modjson = path.join(mods.path, file, "mod.json");
fork icon17
star icon106
watch icon4

+ 53 other calls in file

3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264


DataPacksJob.prototype.rmdirCustom = async function (dir) {
    var list = fs.readdirSync(dir);
    for (var i = 0; i < list.length; i++) {
        var filename = path.join(dir, list[i]);
        var stat = fs.statSync(filename);


        if (filename == "." || filename == "..") {
            // pass these files
        } else if (stat.isDirectory()) {
fork icon80
star icon94
watch icon26

+ 17 other calls in file

306
307
308
309
310
311
312
313
314
315
    console.error(err)
    res.status(400).json({error: err});
} else {
    const cacheFile = path.join(CACHE_PATH, `${cacheId}`);
    mergeFiles(partFiles, cacheFile).then((status) => {
        const cacheFileSize = fs.statSync(cacheFile).size;
        if (cacheFileSize !== size) {
            const err = `Uploaded size mismatch: received ${cacheFileSize} expected ${size}`;
            console.error(err)
            res.status(400).json({error: err});
fork icon6
star icon30
watch icon1

+ 3 other calls in file

function icon

fs-extra.readFileSync is the most popular function in fs-extra (9724 examples)