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
host b is sending an email intented for the user on host a to the mail server what protocol is being used to send the message
KatRina [158]

Answer:

SMTP

Explanation:

This is the SMTP or the Simple Mail Transfer Protocol. It is the push protocol and is used to send the mail message. Whereas POP3 and IMAP are meant for retrieving the message. These are the three main types of protocols associated with mail services. And the correct answer here is certainly the SMTP.

3 0
3 years ago
Which types of computers are used by large businesses
aniked [119]

answer:

Mainframe computers are used by large companies and organisations to perform critical tasks that involve bulk data processing like transaction processing, census information, statistical data and so on. They consist of extensive input and output facilities, are very stable and dependable and handle millions of transactions every day

Explanation:

4 0
3 years ago
you want to implement a protocol on your network that allows computers to find the ip address of a host from a logical name. whi
aniked [119]

The protocol that should be implemented is that one needs to enable hosts on the network to find the IP address.

<h3>What is IP address?</h3>

It should be noted that IP address simply means a unique address that defines a device on the internet.

In this case, the protocol that should be implemented is that one needs to enable hosts on the network to find the IP address.

Learn more about IP address on:

brainly.com/question/24930846

#SPJ12

7 0
2 years ago
An open intersection is one that
alekssr [168]

 open intersection is one without traffic control signs or signals. When you enter one, you must yield the right-of-way if: A vehicle is already in the intersection. You enter or cross a state highway from a secondary road. hope this helped


4 0
4 years ago
Read 2 more answers
In a c program, if you see a variable in main declared: float farray[20]; describe what farray is
Bas_tet [7]
An array of floats that can hold up to 20.
3 0
3 years ago
Other questions:
  • What item on a business card is generally the most prominent?
    13·2 answers
  • If after a run of arc consistency during the backtracking search we end up with the filtered domains of *all* of the not yet ass
    12·1 answer
  • Write a program that sorts a vector of names alphabetically using the selection sort and then searches the vector for a specific
    7·1 answer
  • You are a network technician for a small corporate network. It's been decided that the office needs a wireless network for emplo
    6·1 answer
  • Which of the following illustrations is depicted in the icon that's used to access Windows Help and Support files?
    13·1 answer
  • Five examples of technology in community​
    7·2 answers
  • True or False? You should never move an injured person.<br> True<br> False
    6·1 answer
  • Apply the Fill - Teal, Accent 4, Soft Bevel text effect (the 5th
    12·1 answer
  • DEFINE Problem:
    11·1 answer
  • The IPv6 address for an Ethernet connection begins with FE80::/64. What does this tell you about the address
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!