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
In order to avoid slipping in the shop, your footwear should ___________.
Arisa [49]

Answer:

b

Explanation:

has traction so it can grip

4 0
3 years ago
Harold Lasswell argues that mass media is an extension of information networks and functions that society has always needed. Wha
AnnyKZ [126]

Answer:

The answer to this question as follows:

Explanation:

  • Media communicates you by collecting and delivering information in terms of mass media industries, like print media, publishing, the corporate media, film, TV, and radio.
  • According to "Harold Lasswell" the primary social processes of the press are to Linking different aspects of the social structure and tracking the environment to aim at risks and opportunities.
8 0
3 years ago
What are the benefits of using presentations to organize and deliver information?
bearhunter [10]
Hello.

The benefits of using presentations to organize and deliver information are: it keeps things in order, keeps peoples attention longer, and it looks more professional.
4 0
3 years ago
Where would the information needed to start a computer be stored?
ASHA 777 [7]

Answer:

BIOS software is stored on a non-volatile ROM chip on the motherboard. … In modern computer systems, the BIOS contents are stored on a flash memory chip so that the contents can be rewritten without removing the chip from the motherboard.

Explanation:

8 0
3 years ago
What type of energy do electronic devices use?
Ket [755]
They use electrical energy. Majority of devices that people now use are controlled by semi conductor components. Your answer is they are using electrical energy! But sometimes they do use radiation.
5 0
3 years ago
Other questions:
  • Suppose in a class of 100 students, there is a homework due every week. The professor wants to encourage students to hand in the
    8·1 answer
  • Write a program that asks the user for the name of a text file. the program should display the last 10 lines of the file on the
    13·1 answer
  • I think these might be the answers but im not to sure, so am I right? or wrong? please help
    11·2 answers
  • Why is ssh preferred over telnet for remote connections?
    10·1 answer
  • Justify the need for branching and jump codes in the instruction set using real world scenarios
    6·1 answer
  • Write an algorithm to convert lengh of your house from cm to meter​
    7·1 answer
  • Which computers were the first PCs with a GUI<br> MS-DOS <br> Linux<br> Windows<br> Mac
    7·2 answers
  • GIVING 50 POINTS!
    6·2 answers
  • What is an IF statement used for?
    12·1 answer
  • When is the POST process executed?
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!