const fs = require('fs');
const path = require('path');
const directoryPath = './node';
// Step 1: Read the contents of the specified directory
fs.readdir(directoryPath, (err, files) => {
if (err) {
console.error('Error reading directory:', err);
return;
}
// Step 2: Iterate through the list of files in the directory
files.forEach(file => {
// Step 3: Construct the full path of each file
const filePath = path.join(directoryPath, file);
// Step 4: Get information about each file
fs.stat(filePath, (err, stats) => {
if (err) {
console.error('Error getting file stats:', err);
return;
}
// Step 5: Check if the item is a directory or a file
if (stats.isDirectory()) {
console.log(`Directory: ${file}`);
} else if (stats.isFile()) {
console.log(`File: ${file}`);
}
});
});
});