1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Murrr4er [49]
3 years ago
5

Write a recursive function, displayFiles, that expects a pathname as an argument. The path name can be either the name of a file

or the name of a directory. If the pathname refers to a file, its filepath is displayed, followed by its contents, like so: File name: file_path Lorem ipsum dolor sit amet, consectetur adipiscing elit... Otherwise, if the pathname refers to a directory, the function is applied to each name in the directory, like so: Directory name: directory_path File name: file_path1 Lorem ipsum dolor sit amet... File name: file_path2 Lorem ipsum dolor sit amet... ... Test this function in a new program.
Computers and Technology
1 answer:
Virty [35]3 years ago
8 0

The following code will be used to write a recursive function and display files

<u>Explanation:</u>

#Import required packages

import os

#Define recursive function

#displayFiles() has a single argument

#which may be either pathname or filename

def displayFiles(pathname):

   #if the given argument is pathname for directory

   if (os.path.isdir(pathname)):

       #open the directory

       for item in os.listdir(pathname):

           #append items in the list

           newItem = os.path.join(pathname, item)

           #print each filename

           #call the function recursively

           displayFiles(newItem)    

   #otherwise if the pathname

   #is filename

   else:

       #set the pathname to filename

       filename=pathname

       baseFile = os.path.basename(filename)

       print("File Name: ", baseFile)

       #open the file in read mode

       with open(filename, "r") as file:

           print("Content:")

           #display the contents of the file

           for line in file:

               #print line

               print(line)

           print()

You might be interested in
Supermarket managers who use scanners on the checkout counters to track inventory levels of their products are using a(n) ______
lidiya [134]
Operation Information System, because you are only collecting data on the amount of products leaving the store.
6 0
4 years ago
Write a java program as follows Write a method called powOfTwo that takes an integer as parameter, computes, and outputs it’s sq
Kisachek [45]

Answer:

public static int powOfTwo(int input) {

 return input*input;

}

You will have to call this method in main
for printing it, write

System.out.println(powOfTwo(your number));

in public static void main(str[]args) {

}

8 0
2 years ago
Sara is having a tough time finding the cause of a problem on a computer she is troubleshooting. She found a possible problem bu
sp2606 [1]

<u>I will advise Sara to do research about the problem on the Internet.</u>

<u>Explanation</u>:

Internet is a network that helps in connecting one computer with other globally. Communication between the computers is possible until the computers are connected with to the Internet. Internet helps in getting information from any computer and interacts with the users of the computer.

Sara finds some issue with her computer. She was troubleshooting, but she could not find the exact problem. She was not sure with the problem that she found. It is better for Sara to do research about her problem on Internet and find the solution.

7 0
3 years ago
_______ tools enable people to connect and exchange ideas.
Serggg [28]

Answer:

B

Explanation:

I'm pretty sure it's B because I mean it makes the most sense

Hope I helped a little:)

Have a nice day!!

6 0
4 years ago
Read 2 more answers
Select the correct text in the passage,
sdas [7]

Answer:

The correct sentence is 1.

Explanation:

The most common use of artificial intelligence is email filtering and trading.

4 0
4 years ago
Other questions:
  • Create a class in JobApplicant.java that holds data about a job applicant. Include a name, a phone number, and four Boolean fiel
    13·1 answer
  • Does technology get in the way of learning ?<br> Help Meh ! ♥ Some ideas :D
    14·2 answers
  • Suppose Host A wants to send a large file to host B. The path from Host A to Host B has three links, of rates R1 = 500 kbps, R2=
    13·1 answer
  • Describe some ways that you personally use information technologies differently than you did just a few years ago
    11·1 answer
  • Bob wants to change a single sub heading on a web page to blue color. Which style should Bob apply to the web page?
    5·2 answers
  • What two things can you do to display the entire content of a cell? ​
    5·1 answer
  • What is the function of HTML?
    13·2 answers
  • How to unblock your Wi-fi if it is blocked by your administrator .
    13·1 answer
  • Examples of hybrid computer​
    9·2 answers
  • Use the round function to modify the program to display at most two digits of precision in the output number.
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!