The Programs Available In The Repository Are :
- 1. File Sorter
- 2. File Mover
- 3. File Opener
The Required Modules For The Files To Be Executed Are :
OS Module
- It is a built in moduleSHUTIL Module
- It is a built in module
The Description Of Each Of The File Is As Follows:
1. File Sorter
This script recursively organizes files in a directory by creating separate folders for each file extension and moving the corresponding files into their respective folders.
The Breakdown Of The File :
The script prompts the user to enter a directory path that they want to organize.
It uses the
os.walk
function to traverse the specified directory and its subdirectories, retrieving information about all the files and directories within it.For each file encountered, the script extracts the file extension using
os.path.splitext(file)[1]
.It creates a target directory for the specific file extension, using the uppercase extension as the directory name. If the target directory doesn't already exist, it creates it using
os.mkdir(target_directory)
.The script moves each file to its corresponding target directory using
shutil.move
, and it prints a message indicating the file has been moved. Once all the files have been processed, it prints "File organization completed!" to signify the completion of the organization process.
2. File Mover
This script defines a function move_files that moves all files from a source folder to a destination folder, and then prompts the user to input the paths for the source and destination folders to execute the function.
The Breakdown Of The File :
The code begins by importing the shutil module, which provides functions for file operations, including moving files.
The code defines a function named
move_files
that takes two parameters:source_folder
anddestination_folder
. This function is responsible for moving files from the source folder to the destination folder.Within the
move_files
function, afor
loop is used to iterate over each file in the source folder. It usesos.listdir(source_folder)
to retrieve a list of file names in the source folder.For each file in the source folder, the code constructs the source path by joining the
source_folder
and thefile_name
usingos.path.join()
. Similarly, the destination path is constructed by joining thedestination_folder
and thefile_name
.Inside the loop, the
shutil.move()
function is called to move the file from the source path to the destination path. This function moves the file to the destination folder and removes it from the source folder.After defining the function, the code prompts the user to enter the paths for the source and destination folders using the
input()
function. Finally, themove_files
function is called with the provided source and destination folders to move the files.
3. File Viewer
The script provides a user-friendly interface for navigating and exploring subfolders, viewing files within a selected subfolder, and opening specific files using the default file viewer on the system.
The Breakdown Of The File :
List Subfolders: The program starts by listing all the subfolders present in the specified directory. It displays each subfolder along with an index number, allowing the user to identify and select a subfolder of interest.
Open Subfolder: Once the user selects a subfolder by entering its index number, the program opens that subfolder. It verifies the index entered by the user and constructs the path to the selected subfolder. Then it sets the current_directory variable to the path of the opened subfolder.
View Files: After opening a subfolder, the user can choose the "View files" option. The program lists all the files present in the currently open subfolder. If there are no files, it informs the user accordingly. Otherwise, it displays each file along with an index number.
Open File: If the user wants to open a specific file, they can choose the "Open file" option. The program verifies that a subfolder is currently open and prompts the user to enter the index number of the file they wish to open. Once a valid index is entered, the program constructs the path to the selected file within the open subfolder and opens it using the default file viewer on the system.
Quit: The user has the option to quit the program by selecting the "Quit" option. This exits the program and ends the execution.
GUI Comming Soon :D