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
customer seeks to buy a new computer for private use at home. The customer primarily needs the computer to use the Microsoft Pow
Savatey [412]

Answer:

A 512 GB Solid State Drive (SSD) will be recommended

Explanation:

Recommended hard disk for the installation of Microsoft PowerPoint application is 3 GB and since the computer is a new one it will be best to buy a hard disc with enough room for expansion, performance speed, durability and reliability

Therefore, a 512 GB Solid State Drive (SSD) is recommended as the price difference is small compared to the spinning hard drive and also there is ample space to store PowerPoint training presentation items locally.

8 0
3 years ago
All of the following are true of using the database approach to managing data except Group of answer choices Decentralized manag
kolezko [41]

Answer:

Decentralized management of data

Explanation:

  • The database management approach is one approach based on the improved standard file solution with the use of DBMS and allows for the stimulus access of data with a large number of users.
8 0
3 years ago
W-11/6=4<br><img src="https://tex.z-dn.net/?f=%20%20%5Cfrac%7Bx%20-%2011%20%7D%7B%206%7D%20%20%3D%204" id="TexFormula1" title="
kozerog [31]

step 1, multiply by 6:

x-11 = 4*6 = 24

step 2, add 11:

x = 35

7 0
3 years ago
X = 1 if (A = 1 OR B = 1) OR (A = 0 AND B = 1
Gnoma [55]

Answer:

For question a, it simplifies.  If you re-express it in boolean algebra, you get:

(a + b) + (!a + b)

= a + !a + b

= b

So you can simplify that circuit to just:

x = 1 if b = 1

(edit: or rather, x = b)

For question b, let's try it:

(!a!b)(!b + c)

= !a!b + !a!bc

= !a!b(1 + c)

= !a!b

So that one can be simplified to

a = 0 and b = 0

I have no good means of drawing them here, but hopefully the simplification helped!

4 0
3 years ago
What describes a group of cells?<br> O crowd<br> Orange<br> O set<br> gangle
deff fn [24]

Answer:

A crowd because it makes more sense tho i could be wrong

7 0
3 years ago
Read 2 more answers
Other questions:
  • Shakespeare’s complete works have approximately 3.5 million characters. Which is bigger in file size: Shakespeare’s complete wor
    5·2 answers
  • Lucky Sevens. Given a whole number, compute and display how many digits in the number are 7s. For example, the number of 7s in 3
    8·1 answer
  • What is the block of text at the bottom of the page called?
    7·1 answer
  • Which finger types the return or enter key?
    6·2 answers
  • You rub two red balloons against a wool scarf. What do you think will happen if you place the balloons near each other. Justify
    5·1 answer
  • Write a program in C++ or C that includes two different enumeration types and has a significant number of operations using the e
    15·1 answer
  • Given an initialized String variable outfile, write a statement that declares a PrintWriter reference variable named output and
    12·1 answer
  • Define Indentation
    8·1 answer
  • WHAT ARE SOME PROS AND CONS OF HYDROGEN FUELL CELLS
    11·1 answer
  • Write a program, TwoDimentionalGrid. Ask the user to enter the size of the 2 dimensional array. Here we are not doing any input
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!