Bnlang File Stats
File statistics (or file stats) provide detailed information about a file, such as its size, type, creation date, and last modification date.
In Bnlang, you can use built-in modules to get these details and make decisions in your program, such as checking if a path is a file or a directory.
Example: Getting File Stats
const fs = require("fs");
fs.stat("example.txt", (ত্রুটি, পরিসংখ্যান) => {
যদি (ত্রুটি) {
কনসোল.ত্রুটি("সমস্যা:", ত্রুটি);
ফেরত;
}
কনসোল.লগ("ফাইল?", পরিসংখ্যান.isFile());
কনসোল.লগ("ডিরেক্টরি?", পরিসংখ্যান.isDirectory());
কনসোল.লগ("সাইজ:", পরিসংখ্যান.size);
কনসোল.লগ("তৈরি:", পরিসংখ্যান.birthtime);
কনসোল.লগ("পরিবর্তন:", পরিসংখ্যান.mtime);
});
Common Properties
- isFile() → Checks if the path is a file.
- isDirectory() → Checks if the path is a directory.
- size → Returns the file size in bytes.
- birthtime → The date the file was created.
- mtime → The date the file was last modified.
Best Practices
- Always handle errors when reading file stats.
- Use
isFile()
andisDirectory()
before performing operations. - File sizes are in bytes, so convert them if needed (e.g., KB, MB).
- Use stats to check last modification date for caching or versioning logic.