answer.
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]
2 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]2 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
Write a copy constructor for carcounter that assigns origcarcounter.carcount to the constructed object's carcount. sample output
Drupady [299]

#include <iostream>

using namespace std;

class CarCounter {

  public:

     CarCounter();

     CarCounter(const CarCounter& origCarCounter);

     void SetCarCount(const int count) {

         carCount = count;

     }

     int GetCarCount() const {

         return carCount;

     }

  private:

     int carCount;

};

CarCounter::CarCounter() {

  carCount = 0;

  return;

}

CarCounter::CarCounter(const CarCounter &p){

carCount = p.carCount;

}

void CountPrinter(CarCounter carCntr) {

  cout << "Cars counted: " << carCntr.GetCarCount();

  return;

}

int main() {

  CarCounter parkingLot;

  parkingLot.SetCarCount(5);

  CountPrinter(parkingLot);

  return 0;

}

Sample output:  

Cars Counted: 5

8 0
2 years ago
Read 2 more answers
In a system where Round Robin is used for CPU scheduling, the following is TRUE when a process cannot finish its computation dur
masha68 [24]

Answer:

B. The process will be terminated by the operating system.

Explanation:

When Round Robin is used for CPU scheduling, a time scheduler which is a component of the operating system is used in regulating the operation. A time limit is set for each of the processes to be run.

So, when a process fails to complete running before its time elapses, the time scheduler would log it off and return it to the queue. This queue is in a circular form and gives each of the processes a chance to run its course.

7 0
2 years ago
Seneca has just applied conditional formatting and realizes that she has made a mistake. Which action should she take to fix the
Mama L [17]

Answer:

its b

Explanation:

on edg

3 0
2 years ago
Read 2 more answers
The piston engine uses the ________ to convert the reciprocating motion of the piston into rotary motion.
PSYCHO15rus [73]

The piston engine uses the crankshaft to convert the reciprocating motion of the piston into rotary motion.

<span>The crankshaft is used to convert reciprocating motion of the piston into rotary motion, while the conversion process is called torque, which is a twisting force. Aside from crankshaft, there are a total of four parts of the engine that work together in order to convert the reciprocating motion into rotary motion namely cylinder, or also called the chamber of the piston, the piston itself, and the connecting rod.</span>

5 0
2 years ago
Jim has excellent oral and written communication skills. He enjoys public speaking and wants a job in which he will interact wit
lianna [129]
The best job for Jim would be public relations specialist.
7 0
2 years ago
Read 2 more answers
Other questions:
  • Which option describes wearable technology?
    5·2 answers
  • Let's assume that the smallest possible message is 64 bytes (including the 33-byte overhead). if we use 100base-t, how long (in
    10·1 answer
  • Mr. Cooper would like to customize his Excel software so his students can create an electronic graph in Excel for their lab repo
    6·1 answer
  • Which description of the plain text file format is most accurate?
    11·2 answers
  • The development of the original personal computer (PC) was a(n) __________ innovation at the time, whereas adding a different ki
    8·1 answer
  • Assume the existence of a Window class with a function getWidth that returns the width of the window. Define a derived class Win
    15·1 answer
  • Your revenue is $22,000. Your Cost of Goods is 16,250. Your gross profit is _____________, fill in the blank,.
    14·1 answer
  • When TCP/IP translates a network layer address into a data link layer address, it sends a special ____________ to all computers
    15·2 answers
  • Consider two vectors that are NOT sorted, each containing n comparable items. How long would it take to display all items (in an
    8·1 answer
  • A file concordance tracks the unique words in a file and their frequencies. Write a program that displays a concordance for a fi
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!