This Node.js script automates the organization of files within a specified directory by grouping them into subdirectories based on their file extensions.
- Define Folder Path: Utilizes
path.join(__dirname, "Organise Files")
to set the target folder path. - Check Folder Existence: Employs
fs.access()
to verify the existence of the folder. If it doesn't exist,fs.mkdir()
is invoked to create it. - Read Files: Calls
fs.readdir()
to read the contents of the folder. - Extract File Extension: Uses
path.extname(file).slice(1)
to obtain the file extension from each file. - Create and Move Files: If an extension is present, the script creates a new directory named after the extension (in uppercase) using
fs.mkdir()
, and moves the file into this directory withfs.rename()
.
- Automated Organization: Files are automatically sorted into extension-based folders, making it easier to manage and locate files.
- Time-Saving: Reduces the manual effort required to organize a large number of files.
- Customizable: The script can be modified to suit different organizational preferences or directory structures.
To use this script, simply run it in a Node.js environment. Ensure that you have Node.js installed on your system and that the script has the necessary permissions to read from and write to the file system.
This project is open source and available under the MIT License.
Contributions are welcome! If you have suggestions or improvements, please submit a pull request or open an issue.
If you encounter any problems or have any questions, please open an issue for support.