Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- # Function to search for files matching the given criteria in the specified folder
- def search_files(folder, criteria):
- # Initialize an empty list to store the search results
- results = []
- # Loop through all files in the specified folder
- for filename in os.listdir(folder):
- # Check if the file matches the search criteria
- if criteria in filename:
- # If the file matches the criteria, add it to the results list
- results.append(filename)
- # Return the list of search results
- return results
- # Prompt the user for the search criteria
- criteria = input("Enter the search criteria: ")
- # Set the folder to search
- folder = "C:\\MyFolder"
- # Search for files matching the given criteria in the specified folder
- results = search_files(folder, criteria)
- # Print the top 10 search results
- print("Top 10 search results:")
- for i in range(min(10, len(results))):
- print(f"{i+1}. {results[i]}")
Advertisement
Add Comment
Please, Sign In to add comment