Question

In: Computer Science

You work for the Gotham Times and you wish discover if Bruce Wayne is really Batman....

You work for the Gotham Times and you wish discover if Bruce Wayne is really Batman. We have exfiltrated some files and you will use Python and file forensics to find the string "Batman" in one of the files to prove it once and for all.

First, ask the user for the ABSOLUTE path to Bruce Wayne's folder and save it to a string variable. Next, convert the string from the user to a Path variable. Third, you will list all files in the folder given to you by the user and display the name of each file to the user. Finally, you will open up each file and look for the string "Batman". If Batman is found, let the user know that we have found Batman and what file we found the string in.

# Import required modules

from pathlib import Path

import os

###############################################################

# Part 1: Ask the user for the ABSOLUTE path to Bruce Wayne's

#         folder and save it to a string variable

###############################################################



###############################################################

# Part 2: Convert that string to a Path variable

###############################################################



###############################################################

# Part 3: List all files in the folder and display the name of

#         each file to the user

###############################################################



###############################################################

# Part 4: Open up each file and look for the string "Batman".

#         If Batman is found, let the user know that

#         we have found Batman and what file we found the

#         string in

#

#         HINT: Here is an example of looking for a substring

#               within a string varible (we'll call the variable

#               fileContents) (from previous lessons)

#

#         if "Batman" in fileContents:

#            print("Found Batman!!")

###############################################################



Solutions

Expert Solution

OS

this module is a efficient way of using the operating system dependent functions. If you just want to read or write a file you can uses open(), if you want to play with systems paths or locations you can use os.path it is a very handy module which let you do file searching and many more OS operations

#importing a module which is important for the operating system activities 
import os
from pathlib import Path

#getting input from user
str_path = input("enter the path to bruce wayn's folder and it should be correct")

#converting string to the operating system path (this step can be optional because os.listdir() function can take string values)
path = Path(str_path)

#getting all the files name from that directory / path
file_list=os.listdir(path)

#displaying every file name that is in that folder
print(file_list)

#traversing through each file and each line in that file through this loop
for files in file_list:
    file=open(files,'r')
    for line in file:
        for word in line.split():
            if word=="Batman":
                print("found Batman!!")

Related Solutions

You wake up and discover that you ache and feel uncomfortable. You really want to go...
You wake up and discover that you ache and feel uncomfortable. You really want to go back to bed, but know that other members of the operating room team are depending on you to be there for a very full and busy day. You go to work, only to find that another member of the team is out sick and you’ll have extra assignments today. As you begin to prepare for your first operating room session, your nose starts running...
Suppose you wish to be outstanding in your field by studying plant cell biology. You discover...
Suppose you wish to be outstanding in your field by studying plant cell biology. You discover a new strain of wild lima bean plants from Costa Rica that is resistant to being killed by a hydrophobic pesticide. Which one of the following states the most reasonable hypothesis that could explain the nature of the pesticide resistance? A) Many chloroplast proteins are encoded in the plant nuclear genome. A nuclear gene encoding an enzyme involved in the dark reactions might confer...
you report to work and discover the office is short staffed for the day you are...
you report to work and discover the office is short staffed for the day you are feeling the pressure for time and know that you need to keep the physicians on track with their scheduled patient you also have patient scheduled for labs your first patient arrives for labs and you gather all your necessary supplies as you are ready to perform the venipuncture your patient faints what do you do
You report to work and discover the office is short-staffed for the day. You are feeling...
You report to work and discover the office is short-staffed for the day. You are feeling the pressure for time and know that you need to keep the physicians on track with their scheduled patients. You also have patients scheduled for labs. Your first patient arrives for labs, and you gather all your necessary supplies. As you are ready to perform the venipuncture, your patient faints. What do you do?
You are considering a new delivery system and wish to test whether delivery times are significantly...
You are considering a new delivery system and wish to test whether delivery times are significantly different on average than your current system. It is well established that the mean delivery time of the current system is 2.38 days. A test of the new system shows that with 48 observations the average delivery time is 1.91 days with a standard deviation of 0.43 day. A) perform a two-sided test at the 1% significance level and describe the result. B) State...
The company you work for provides you with 20 random wish bone samples to calculate the...
The company you work for provides you with 20 random wish bone samples to calculate the yield strength of a material used in your production proccess. The data calculated is provided below. The steel you recieve is reported to have a mean of 420 with a standard deviation of 5 MPa. yield_strength = c(444,435,465,423,425,470,417,418,410,399,425,423,459,465,420,423,417,404,420,451) a Can you run a HT with this data? Why? b Assuming you can, calculate the standard error and margin of error with an alpha level...
How important do you think group identification really is to an individual's motivation to work on...
How important do you think group identification really is to an individual's motivation to work on a task? Do you think this could differ between individuals? What other factors would be relevant?
Hiring the right employee enhances your work culture and pays you back a thousand times over...
Hiring the right employee enhances your work culture and pays you back a thousand times over in high employee morale, positive forward-thinking planning, and accomplishing challenging goals. It also ensures that you are making the most of the time and energy that your other employees invest in a relationship with the new employee—a costly and emotional process, indeed. Your task is to identify two (2) employees you need to run your business. For each employee, provide a purpose, job description...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT