Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Topic Video
Question
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... ...
# Put your code here
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 item in os.listdir(pathname):
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
newitem = os.path.join(pathname, item) #
#contents = os.path.join(pathname, content) #joins contents of path
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps with 1 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Using visual studio (C#) create a program, name it PRGYOURNAMEFA1, that implements a search and replace function recursively. Your program should allow a user to enter a string , a substring to be replaced in the entered string and a character/s to replace the found substring Program Structure1. A main class that implements the logic of the program – name this class TestSearchReplace2. Add a class named SearchReplace to the main class with two methods, including:a. SearchSubstring()- return methodb. ReplaceSubString() - void method The two method should be called using an object in the main class. DONT CREATE THE TWO METHODS IN THE MAIN CLASSSample Outputarrow_forwardWrite a c++ function that accepts an array of doubles and the array’s size as its only arguments. The function should use dynamic memory allocation to create a new array that is double the size of the argument array. The function should copy the contents of the argument array to the second half of the new array and initialize the first half of the new 0s. The function should return a pointer to the new array. So, if the original array contained 1 2 3 4, the new array should contain 0 0 0 0 1 2 3 4. So, if the original array contained 1 2 3 4, the new array should contain 0 0 0 0 1 2 3 4.arrow_forwardWrite a menu-driven C++ program to manage your college course history and plans, named as you wish. It should work something like this: Array size: 0, capacity: 2MENUA Add a courseL List all coursesC Arrange by courseY arrange by YearU arrange by UnitsG arrange by GradeQ Quit...your choice: a[ENTER]Enter a courses' name: Comsc-165[ENTER]Enter the year for Comsc-165 [like 2020]: 2016[ENTER]Enter the units for Comsc-165 [0, 1, 2,...]: 4[ENTER]Enter the grade for Comsc-165 [A, B,..., X if still in progress or planned]: x[ENTER]Array size: 1, capacity: 2MENUA Add a courseL List all coursesC Arrange by courseY arrange by YearU arrange by UnitsG arrange by GradeQ Quit...your choice: a[ENTER]Enter a courses' name: Comsc-110[ENTER]Enter the year for Comsc-110 [like 2020]: 2015[ENTER]Enter the units for Comsc-110 [0, 1, 2,...]: 4[ENTER]Enter the grade for Comsc-110 [A, B,..., X if still in progress or planned]: A[ENTER]Array size: 2, capacity: 2MENUA Add a courseL List all coursesC Arrange by…arrow_forward
- In C++, Write a program that will inputstudent’s information (i.e. name, id, cgpa) who have enrolled forCSE-207 course in Spring 2022. You have to declare a pointer variable to inputthe information and dynamically allocate memory for storing information of eachstudents. You have to implement the following operation.i) Create a list with the given studentsinformationii) Delete a student of a given idiii) Print the student having highest CGPAiv) Sort and print the student id and namedescending order based on the CGPA.arrow_forwardWrite a c program for a simple student record.Each record should contain the following information:● Surname – a string (surname of the student)● Sex – a character (M for male, F for female)● Year – an integer (year part of student number)● Snum – an integer (last five digits of the student number)● Department – a string (department the student is a part of)Your program should be able to allow the user to:● Add records● Display all records● Display all records filtered by sex/ year/ department● Display record(s) linked to a given snum (last five digits of a student number)Note: student number should be displayed following the format year - snumarrow_forwardAdd a function to get the CPI values from the user and validate that they are greater than 0. 1. Declare and implement a void function called getCPIValues that takes two float reference parameters for the old_cpi and new_cpi. 2. Move the code that reads in the old_cpi and new_cpi into this function. 3. Add a do-while loop that validates the input, making sure that the old_cpi and new_cpi are valid values. + if there is an input error, print "Error: CPI values must be greater than 0." and try to get data again. 4. Replace the code that was moved with a call to this new function. - Add an array to accumulate the computed inflation rates 1. Declare a constant called MAX_RATES and set it to 20. 2. Declare an array of double values having size MAX_RATES that will be used to accumulate the computed inflation rates. 3. Add code to main that inserts the computed inflation rate into the next position in the array. 4. Be careful to make sure the program does not overflow the array. - Add a…arrow_forward
- In C++ please and thank you!arrow_forwardCode in C Code in the file IO: /************************************************************* This program prints a degree-to-radian table using a for- loop structure. The results are printed to a file and the the screen. *************************************************************/ #include <stdio.h> #define PI 3.141593 #define FILENAME "tableD2R.dat" int main(void) { /* Declare variables. */ double radians; FILE *fileout; /* Open file. */ fileout = fopen(FILENAME,"w"); if (fileout == NULL) printf("Error opening input file. \n"); else { /* Print radians and degrees in a loop. */ printf("Degrees to Radians \n"); for (int degrees=0; degrees<=360; degrees+=10) { radians = degrees*PI/180; printf("%6i %9.6f \n",degrees,radians); fprintf(fileout,"%6i %9.6f \n",degrees,radians); } /* Exit program. */ }arrow_forwardComputer Science A system call in an operating system is typically a function call that traps to the kernel. However, there are also library calls that are functions that do not directly trap into the kernel, but may invoke system calls that do. In MINIX, there is a corresponding library call read that always invokes the system call. In UNIX, there are also several other library calls---getc, fgetc, getchar, for example---that also input data. Describe the difference between the MINIX read library call and these functions. How do you think these functions (getc, fgetc, getchar) perform data input? Do they always need to ultimately trap to the kernel? Why or why not?arrow_forward
- Write a C/C++ program that: Writes a function, readFile(), that reads the content of the provided text file “stnumbers.txt” and stores it in an array of Student structs. The function receives as parameter an array of type Student structs. The number of lines that was read from the text file must be returned to the calling statement. If the file cannot be read, an error message should be displayed. stnumbers.txt textfile is given below Peterson20570856Johnson12345678Suku87654321Westley12345678Venter87654321Mokoena79012400Makubela29813360Botha30489059Bradley30350069arrow_forwardWrite a function IN C LANGUAGE that splits the following data read from a file named info.txt and store the data into a struct as show in the example: typedef struct{char name[20];char gender[5];char dateOfAdmission[20];char dateOfBirth [20];char illness [20];char address [20];char bloodType[5]; } information; Abed Mukhles#M#2212019#01012000#Ear Infection#Jenin#O+ Here the values are: name:Abed Mukhles gender:M dateOfAdmission:2212019dateOfBirth:01012000illness:Ear Infectionaddress:JeninbloodType:O+ Same for:Nadia A. Ali#F#01102020#05101970#COVID-19#AlBireh#A-arrow_forwardAdd file i/o to your program Implement a function writeEmpToFile that takes two arguments: a struct Employee pointer and a FILE *. It should write each field in order as an appropriate type. Note that you will probably want to write a length of the name before you write the characters of the name. By doing this, when you write the load function below, you can read the length of the string and use it to malloc a buffer of the proper size to hold the name. Because of the embedded name pointer, you CAN NOT write the Employee struct as a single struct. You will need to write it out field by field. You will want to write this as a binary file, not as a text file. Implement a SAVE command in your main loop that will save all the employees out to a file. The SAVE command should ask for a file name, similar to the way your FIND command asked for a name. Implement a function readEmpFromFile that takes a FILE * as the only argument and returns a pointer to a struct employee. This function should…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education