file-organizer-cli
Version:
A powerful and easy-to-use CLI tool to organize files into folders by type.
42 lines (34 loc) ⢠918 B
JavaScript
const path = require('path');
const fs = require('fs/promises');
const { organizeFolder } = require('../lib/organizer');
(async () => {
const input = process.argv[2];
if (!input || input === '--help') {
console.log(`
š File Organizer CLI
š Usage:
organize <folder-path>
š¦ Example:
organize ./Downloads
`);
process.exit(0);
}
const targetPath = path.resolve(input);
try {
const stat = await fs.stat(targetPath);
if (!stat.isDirectory()) {
console.error('ā Error: Provided path is not a folder.');
process.exit(1);
}
} catch {
console.error('ā Error: Provided folder does not exist.');
process.exit(1);
}
try {
await organizeFolder(targetPath);
console.log('ā
Files organized successfully.');
} catch (err) {
console.error(`ā Error: ${err.message}`);
}
})();