Helper Functions
Step 6: Implement Helper Methods
Now, we'll implement helper methods for each of the actions (clear_bin
, recycle_file
, recycle_all
, and search_file
).
6.1: clear_bin
Method
This method clears the recycle bin using the winshell.recycle_bin().empty()
function.
empty()
: Empties the recycle bin.The method checks if there are items in the recycle bin before attempting to clear it.
6.2: recycle_file
Method
This method restores a specific file from the recycle bin using its file path.
undelete(file_path)
: Restores the file from the recycle bin by its original path.
6.3: recycle_all
Method
This method restores all items in the recycle bin by calling undelete()
on each item.
item.original_filename()
: Retrieves the original file path of each item in the recycle bin.
6.4: search_file
Method
This method searches for files in the recycle bin by their name (or partial name). It returns a list of matching files.
os.path.basename()
: Extracts the file name from the full path.We use case-insensitive matching to check if the given
file_name
is part of any files in the recycle bin.
Last updated