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
Anika [276]
4 years ago
6

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:
Computers and Technology
1 answer:
timama [110]4 years ago
8 0

Answer:

Here is the Python function:

import os   #module used to interact with operating system

def displayFiles(pathname):  #recursive function that takes a pathname as argument

  if (os.path.isdir(pathname)):  #checks if specified path (argument) is an existing directory

      for content in os.listdir(pathname):  #gets the list of all files and directories in the directory and iterates through the items of this list of directory

          contents = os.path.join(pathname, content)  #joins contents of path

          displayFiles(contents)  #calls function recursively

  else:  #if pathname refers to a file

      filename=pathname  #sets filename to pathname

      file = os.path.basename(filename)  #gets base name in specified path

      print("File Name: ", file) #displays the name of file

      with open(filename, "r") as contents:  #opens file in read mode

          print("Content:")  #prints Content:

          for lines in contents:  #iterates through the contents of file

              print(lines)   #displays the contents of file

Explanation:

The recursive function  displayFiles contains a single argument  pathname which can either be a pathname or a filename  . If the given argument is pathname for directory  , then the directory is opened and os.listdir returns a list containing the names of the entries in the directory given by pathname and append these contents in the list. Then this function is called recursively to print each file name and this function is applied to each name in the directory. However if the pathname refers to a file then the pathname is set to filename , the file is opened in read mode and the contents of the file are displayed.

You might be interested in
There are several methods of updating information and data on a webserver. We must consider who performs those updates upfront w
Thepotemich [5.8K]

Answer:

RTMC pro, HTML server-sent and Java Software Development Kit

Explanation:

<u>RTMC pro</u>:  The setup of RTMC pro is done automatically and there is provision of several elements to upload and store data on the server using screens. Screens are usually saved as files and then integrated to an internal or external server.

<u>HTML server-sent</u> : This is a way for webpages to communicate with the webserver. In this method, for ever HTML page there is an associated script present on the server side that will continuously provide realtime data update. This scrip will have to be configured with the data you want to update.

<u>Java Software Development Kit</u> : JAVA SDK is used to build software/applications on Java. This permits programmers to develop applications or applets to perform data updating on the servers. The developped applets can be used with internal servers as well as third party servers.

5 0
3 years ago
Read 2 more answers
âin order to aid a forensics investigation, a hardware or software ______________ can be utilized to capture keystrokes remotely
faltersainse [42]
(keystroke) logger. I'm hoping this is what you wanted.
5 0
4 years ago
Define Auxiliary memory?​
andrew-mc [135]

Answer:

An Auxiliary memory is referred to as the lowest-cost, highest-space, and slowest-approach storage in a computer system. It is where programs and information are preserved for long-term storage or when not in direct use. The most typical auxiliary memory devices used in computer systems are magnetic disks and tapes. :)

5 0
3 years ago
Read 2 more answers
[10 points] Write a program to compute the sum of digits in a number given by the user. You must use your own function to comput
Zielflug [23.3K]

Answer:

I am going to write the program using BASIC PROGRAMMING

Explanation:

10 PROGRAM TO CALCULATE SUM OF DIGITS

20 INPUT B,H,T,G

30 LET Y = B+H+T+G

40 PRINT Y

DO THIS ON BASIC PROGRAMMING AND YOU HAVE YOUR PROGRAM

3 0
3 years ago
Write code that inserts userItems into the output string stream itemsOSS until the user enters "Exit". Each item should be follo
Yuki888 [10]

Answer:

The solution code is written in Python:

  1. itemsOSS = ""
  2. userItem = input("Enter an item: ")
  3. while(item != "Exit"):
  4.    itemsOSS += userItem + " "
  5.    userItem = input("Enter an item: ")
  6. print(itemsOSS)

Explanation:

Firstly, we create a variable itemsOSS (intialized it with empty string) and use it as output string stream (Line 1).

Next use input function to prompt user to enter first item (Line 2)

While the item value is not "Exit" (Line 4), append userItem to variable itemsOSS.

When the user enter "Exit", use print function to print the itemsOSS string (Line 8).

8 0
3 years ago
Other questions:
  • You have installed a streaming video service on your network. You want selected hosts to be able to access this service via a dy
    6·1 answer
  • Which view in file explorer can use to sort files by column heading
    8·1 answer
  • Which structure is the following true for? For _________, arguments are substituted exactly as entered, without checking for mem
    6·1 answer
  • in a mechanism ,when the input goes from a small gear to an output which is a larger gear the speed will _____
    10·1 answer
  • Which of the following is a component of slides
    10·1 answer
  • Design state machines to control the minutes and hours of a standard 24 hour clock. Your clock should include an AM/PM indicator
    11·1 answer
  • Draw the resistor’s voltage and current phasors at t=15ms. Draw the vectors with their tails at the origin. The orientation of y
    5·2 answers
  • The term packet is used fairly generically to refer to protocol data unit (PDU). There are PDU equivalent names in the different
    15·1 answer
  • Which one way in which using infrared in game console controllers could affect the experience of a person playing the game?
    8·1 answer
  • Comment suprimer son compte brainly
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!