abnormal
Error: EBUSY: resource busy or locked, stat 'C:\swapfile.sys'
at Object.statSync (node:fs:1536:3)
at D:\NodeJs\node-demo\demo\world.js:7:24
at FSReqCallback.oncomplete (node:fs:188:23) {
errno: -4082,
syscall: 'stat',
code: 'EBUSY',
path: 'C:\\swapfile.sys'
}
Node.js v17.1.0
error code
var fs = require('fs');
var rootPath = 'C:\\';
fs.readdir(rootPath, function (err, files) {
for (var i = 0; i < files.length; i++) {
var p = rootPath + files[i];
var stats = fs.statSync(p);
console.log(rootPath + 'Is it a directory:' + stats.isDirectory())
}
});
Reason
Prompt error: EBUSY: resource busy or locked, stat
indicates that the resource file is busy or locked, that is, the C:\swapfile.Sys
file. But there is no such file in the C disk directory, even in the hidden file. But it can be found by opening everything software
is a system file.
Solution:
I don’t know how to solve it. The online solution seems to be invalid, so I can only block the file.
Correct code
var fs = require('fs');
var rootPath = 'C:\\';
fs.readdir(rootPath, function (err, files) {
for (var i = 0; i < files.length; i++) {
var p = rootPath + files[i];
// Skip when encountering swapfile.sys file or System Volume Information directory
if (p.endsWith('swapfile.sys') || p.endsWith('System Volume Information')) {
continue;
}
var stats = fs.statSync(p);
console.log(rootPath + 'Is it a directory:' + stats.isDirectory())
}
});
Read More:
- [Solved] Error: EBUSY: resource busy or locked, lstat ‘D:\DumpStack.log.
- [Solved] Error: ENOENT: no such file or directory, scandir ‘..\node_modules\node-sass\vendor‘
- node.js yarn Error: SyntaxError: Unexpected string [How to Solve]
- [Solved] Node.js v17 npm run dev Error: opensslErrorStack
- [Solved] node.js Upload Files Error: Multipart: boundary not found multer
- Node.js Error: Error: Cannot find module ‘express‘ [How to Solve]
- [Solved] Node.js: Error: connect ECONNREFUSED ::1:3306
- [Solved] NPM node ERROR in main..js from Terser ChildProcessWorker.initialize Excaption
- Node.js Error: Cannot find module express [How to Solve]
- [Solved] node.js request Error: Error: unable to verify the first certificate
- [Solved] This dependency was not found: * core-js/modules/es.error.cause.js in ./node_modules/_@babel_runtim
- Error: Rule can only have one resource source (provided resource and test + include + exclude)
- [Solved] Uncaught DOMException: Failed to execute ‘readAsDataURL‘ on ‘FileReader‘: The object is already busy
- [Solved] Vue-cli3 running or packaging error: JS memory overflow
- [Solved] error C:\Users\HP\Desktop\VueProject\vue_cli\node_modules\node-sass: Command failed.Exit code: 1
- [Solved] Error Rule can only have one resource source (provided resource and test + include + exclude)
- [Solved] Error Rule can only have one resource source (provided resource and test + include + exclude)
- [Solved] Nuxt Import qrcodejs2.js / QRCode.js Error: document is not defined
- Solution to some map files in JS folder after Vue packaging (remove the map. JS file)
- [Solved] Vue Error: Error: Rule can only have one resource source (provided resource and test + include + ex