How to use the lstatSync function from fs

Find comprehensive JavaScript fs.lstatSync code examples handpicked from public code repositorys.

57
58
59
60
61
62
63
64
65
66
    }
}

static isDirectory(fileName) {
    try {
        return fs.lstatSync(fileName).isDirectory();
    } catch (e) {
        return false;
    }
}
fork icon156
star icon0
watch icon32

+ 15 other calls in file

216
217
218
219
220
221
 * @param  {string}  dir - directory path
 * @return {boolean} is directory
 */
exports.isdir = function (dir) {
    try {
        return fs.lstatSync(dir).isDirectory();
fork icon124
star icon815
watch icon42

+ 30 other calls in file

60
61
62
63
64
65
66
67
68
69
exports.lchown = co.promisify(fs.lchown);
exports.lchownSync = fs.lchownSync;
exports.link = co.promisify(fs.link);
exports.linkSync = fs.linkSync;
exports.lstat = co.promisify(fs.lstat);
exports.lstatSync = fs.lstatSync;
exports.mkdir = co.promisify(fs.mkdir);
exports.mkdirSync = fs.mkdirSync;
exports.mkdtemp = co.promisify(fs.mkdtemp);
exports.mkdtempSync = fs.mkdtempSync;
fork icon22
star icon45
watch icon26

685
686
687
688
689
690
691
692
693
694
    if (mkParent)
      return this[ONERROR](mkParent, entry)
  }
}

const [lstatEr, st] = callSync(() => fs.lstatSync(entry.absolute))
if (st && (this.keep || this.newer && st.mtime > entry.mtime))
  return this[SKIP](entry)

if (lstatEr || this[ISREUSABLE](entry, st))
fork icon3
star icon2
watch icon0

29
30
31
32
33
34
35
36
37
38

if (options.root) {
  this.root = options.root
} else {
  try {
    sysFS.lstatSync('./public')
    this.root = './public'
  } catch (err) {
    this.root = './'
  }
fork icon2
star icon11
watch icon11

58
59
60
61
62
63
64
65
66
67
if(!fs.existsSync(modelbasedir)){ _this.LogInit_ERROR('Model folder ' + modelbasedir + ' not found'); return; }
var fmodels = fs.readdirSync(modelbasedir);
for (let i in fmodels) {
  var fname = fmodels[i];
  var fpath = modelbasedir + fname;
  var fstat = fs.lstatSync(fpath);
  if(fstat.isDirectory()){
    if(options.isBaseDir){
      if(fname=='js') continue;
      if(fname=='sql') continue;
fork icon5
star icon5
watch icon2

63
64
65
66
67
68
69
70
71
72
folder_list = [];
file_list = [];

files.forEach(function (file) {
  const filePath = d + "/" + file;
  const fileStat = fs.lstatSync(filePath);

  if (fileStat.isDirectory()) {
    folder_list.push(file);
  } else {
fork icon1
star icon2
watch icon1

+ 3 other calls in file

282
283
284
285
286
287
288
289
290
291
 * Gets file stats
 * @param pathToElement
 * @returns {*}
 */
lstatSync(pathToElement) {
  return fs.lstatSync(pathToElement);
}

createReadStream(pathToElement, options) {
  return fs.createReadStream(pathToElement, options);
fork icon0
star icon4
watch icon2

84
85
86
87
88
89
90
91
92
93
// Checks that a given filename is valid
function checkFileStr (str, ref) {
    if (typeof(str) != "string" || str == "") {
        throw new userError(`The value of ${ref} is invalid. \nFix the value, or remove the attribute if you do not intend to use it.`);
    }
    if (!(fs.existsSync(str) && fs.lstatSync(str).isFile())) {
        let fileStr = str[0] == "/" ? str : `${__dirname}/${str}`
        throw new userError(`${ref}: File "${fileStr}" does not exist.`);
    }
}
fork icon0
star icon2
watch icon2

+ 3 other calls in file

43
44
45
46
47
48
49
50
51
52
 * to one string.
 * @param {String} filePath
 */
const readComponentCode = filePath => {
  let code = '';
  const isItFolder = fs.lstatSync(filePath).isDirectory();
  if (isItFolder) {
    const contents = fs.readdirSync(filePath);
    contents.forEach(file => {
      code += readComponentCode(path.join(filePath + '/' + file));
fork icon0
star icon1
watch icon0

+ 3 other calls in file

28
29
30
31
32
33
34
35
36
37

const files = fs.readdirSync(folder);
const htmls = [];
for (var i = 0; i < files.length; i++) {
  var filename = path.join(folder, files[i]);
  var stat = fs.lstatSync(filename);
  if (stat.isDirectory()) {
    var recursed = findHtml(filename);
    for (var j = 0; j < recursed.length; j++) {
      recursed[j] = path.join(files[i], recursed[j]).replace(/\\/g, '/');
fork icon382
star icon0
watch icon32

125
126
127
128
129
130
131
132
133
fs.symlinkSync(file2, link);

fs.lchmod(link, mode_async, common.mustCall((err) => {
  assert.ifError(err);

  assert.strictEqual(mode_async, fs.lstatSync(link).mode & 0o777);

  fs.lchmodSync(link, mode_sync);
  assert.strictEqual(mode_sync, fs.lstatSync(link).mode & 0o777);
fork icon16
star icon65
watch icon0

99
100
101
102
103
104
105
106
107
108
109
    return true;
  };


  fs.lstat(nonexistentFile, common.mustCall(validateError));
  assert.throws(
    () => fs.lstatSync(nonexistentFile),
    validateError
  );
}

fork icon42
star icon19
watch icon0

87
88
89
90
91
92
93
94
95
96

// console.log(childNames)

for(let i =0; i<childNames.length; i++){
    let childAddress = path.join(src,childNames[i])
    let isFile = fs.lstatSync(childAddress).isFile();
    
    if(isFile){                                         //differeniating file and directory
        
        // console.log(childNames[i])
fork icon0
star icon0
watch icon1

78
79
80
81
82
83
84
85
86
87
88
89
90
91


function treeHelper(dirPath,indent){


    // is file or folder


    let isFile = fs.lstatSync(dirPath).isFile();


    if(isFile)
    {
        let fileName = path.basename(dirPath)
fork icon0
star icon0
watch icon1

72
73
74
75
76
77
78
79
80
81
    }
}
function getFiles(srcpath, schema) {
    return fs.readdirSync(srcpath).filter((file) => {
        
            return fs.lstatSync(path.join(srcpath, file)).isFile() && verify.endsWith(file, (schema === 'ittf' ? '.ittf' : '.' + schema + '.ittf'));
        }
        )
    ;
}
fork icon0
star icon0
watch icon2

294
295
296
297
298
299
300
301
302
303
  files = fs.readdirSync(dir);

for (var i = 0, length = files.length; i < length; i++) {
  var
    file = path.join(dir, files[i]),
    stat = fs.lstatSync(file); // lstat so we don't recurse into symlinked directories

  if (stat.isDirectory()) {
    if (!deferred) {
      deferred = true;
fork icon0
star icon0
watch icon1

15
16
17
18
19
20
21
22
23
24
25


function* walkDirectory(directory, filter) {
  // Generator for recursively walk a directory.
  for (const filePath of fs.readdirSync(directory)) {
    const currentPath = path.join(directory, filePath);
    const stat = fs.lstatSync(currentPath);
    if (stat.isFile()) {
      if (!filter || filter(currentPath)) {
        yield currentPath;
      }
fork icon0
star icon0
watch icon1

+ 2 other calls in file

391
392
393
394
395
396
397
398
399
400
if (path.isAbsolute(resource)) {
  sourcePath = path.dirname(resource);
  resource = path.basename(resource);
}

const isFolder = fs.lstatSync(path.join(sourcePath, resource)).isDirectory();
if (isFolder) {
  const pathFolder = path.join(sourcePath, resource);
  const ns = namespace.slice(0);
  ns.push(resource);
fork icon0
star icon0
watch icon262

25
26
27
28
29
30
31
32
33
34
is_busy = true
delete require.cache[file_path]

try {
	require(file_path)
	mtimeMs = lstatSync(file_path).mtimeMs
	is_busy = false
	module.exports.load(require("../../events/ready").bot)
} catch (exception) {
	console.log(`[${file_path.split(sep).pop()} ERRORED | RELOADING IN 5 SECONDS]: ${exception}`)
fork icon0
star icon0
watch icon1

+ 5 other calls in file