This Python script serves as a file organizer, streamlining the process of sorting various types of files into designated folders. It utilizes the 'os' and 'shutil' libraries for interacting with the operating system and managing file operations, respectively.
Here's how it works:
-
Folder Creation: The script first creates several folders within a specified directory to categorize different file types. These folders include:
- 'JupyterNotebook files' for Jupyter notebook files.
- 'CSV & Excel files' for CSV and Excel data files.
- 'Python files' for Python script files.
- 'Text files' for text-based files.
- 'Other files' for any remaining file types.
-
File Organization: It then iterates through each file in a specified directory, determining its type based on file extension. Depending on the file type:
- Jupyter notebook files (.ipynb) are moved to the 'JupyterNotebook files' folder.
- CSV and Excel files (.csv, .xlsx) are relocated to the 'CSV & Excel files' folder.
- Python script files (.py) are transferred to the 'Python files' folder.
- Text files (.txt) are sorted into the 'Text files' folder.
- All other file types are moved to the 'Other files' folder.
-
Error Handling: The script includes error handling mechanisms to ensure smooth execution. If any errors occur during the file-moving process, it logs the error and continues with the remaining files.
-
Feedback: Throughout the process, the script provides feedback by printing messages indicating the successful movement of files or any encountered errors.
Overall, this script demonstrates the power of Python in automating routine tasks, such as file organization, thereby enhancing efficiency and productivity in daily workflows.