DoubleMega, the company that you work for needs a more advanced search program for their IT help desk. They need one program that can work on multiple, different, operating systems so they have asked you to write one (vs. use an existing tool). The tool should use one regular expression to match the file names and a different regular expression to match lines within the file.
The program should do the following:
1. Ask the user for three things
a. A directory that to search (it may contain subdirectories within it)
b. A regular expression to match the filename
i. Matches are against the FULL filename, and not just the name within the directory
ii. So, if the user types in “b” as the regular expression, the following files would match
1. /dir1/dir2/bat.txt
2. /dir1/dir2/file.bmp
3. /dir1/backup/file1.txt
c. A regular expression to match lines within the file
2. Search all files within the directory, and traverse any subdirectories in it
3. Handle .tar or .zip files within the directory
a. For full-credit, you must handle one of these
b. Extra credit will be given if you can handle both of these
c. For a small “penalty”, you may elect not to handle neither
i. (if you do so, you can only earn 10 out of the max 12.5 points in Specification)
d. You do not need to handle .zip and .tar files within .zip and .tar files
i. (So no recursion is necessary)
4. Indicate the full filename (aka the whole path) to the file, a colon and a space, and the line it matched.
a. See the sample runs on the next page
5. You may use Python, Java, or any other language with prior instructor approval.

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

import os # os module for walking directories
import re # re module for regex
import tarfile # tarfile module for reading .tar files
import zipfile # zipfile module for reading .zip files

# Main method
def main():
    # Query directory
    directory = input('Enter directory to search                   : ')
    # Query filename regex
    filename_regex = input('What files do you want to match (use RegExp) : ')
    # Query line regex
    line_regex = input('What lines do you want to match (use RegExp) : ')
    # Gather all files and directories in directory
    for root, dirnames, filenames in os.walk(directory):
       # Iterate over filenames
       for filename in filenames:
            filename = os.path.join(root, filename)
            # Check .tar files
            if filename[-4:] == '.tar':
                tar =, mode='r')
                # Check files inside of .tar file
                for tarmember in tar.getmembers():
                   tarfilename = os.path.join(filename...
$45.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Python Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Upload a file
Continue without uploading

We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats