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
alexira [117]
3 years ago
9

Write a Unix (Linux) find-like command (myFind) in Python3 where the function will return the full paths of all the files contai

ning the specified substring at the command line by recursively searching all the files and subdirectories starting from the specified directory. At the end of the command, it also returns the total file size of those files found in bytes . The total file size should be the summation of the file sizes of the regular files only.
Computers and Technology
1 answer:
Leno4ka [110]3 years ago
5 0

Answer:

import os, sys, stat

from stat import *

command = 'find ' + sys.argv[1] + ' -name *' + sys.argv[2] + '*'

print(command)

totalFiles = os.popen(command).read()

totalFiles = totalFiles.split()

totalSize = 0

for line in totalFiles:

  statinfo = os.stat(line)

 

  if stat.S_ISREG(statinfo.st_mode):

      print(line, statinfo.st_size, 'bytes')

      totalSize += statinfo.st_size

  else:

      print(line, '...')

print('Total file size:', totalSize, 'bytes')

Explanation:

  • According to command line arguments, build the find command.
  • Store the product by executing the command.
  • Loop through all files in the output list using the for loop.
  • Display the file name and size, If the file is regular otherwise just display the file name.
You might be interested in
How are clustering and Network Load Balancing similar?
Elza [17]

Answer:

Load balancing is the mechanism happening between the different components to achieve the aim independently in the server. They are not aware of the presence of the other resources with them.

Clustering is the process in which the components work to gain the desired results in the form of group.They work in group so that there are no chances of crash  in server.

The similarity arises between these two process are :

  • They have capability to work even after failure of system
  • Can have unnecessary access to the information
  • Scalable

5 0
3 years ago
How to enhance the video to full screen in filmora
Anastaziya [24]

Answer:

The answer to your question is to click on the button with the square on the window options ribbon.

6 0
3 years ago
Use the code below to answer the following questions. Note that the catch statements in the code are not implemented, but you wi
anzhelika [568]

Answer:

d) either e1 or e5

Explanation:

Here, the instruction i1 goes ahead in trying to open the given file through an input stream buffer reader. If the given file name is wrong, it will indicate that an e1 file is not found or if any other IO errors due to invalid stream, no disc in drive e5 IO exception will be drawn.

4 0
3 years ago
Leah deals with several file conversions every day.
Lelechka [254]
That’s not a question but good for her
5 0
3 years ago
How to tell if screen or screen protector is cracked?
beks73 [17]
You will feel the screen protector crack
6 0
3 years ago
Read 2 more answers
Other questions:
  • If you’d like to have multiple italicized words in your document, how would you change the font of each of these words?
    7·2 answers
  • HTTP is made to facilitate which kind of communication?
    11·1 answer
  • Which of these options would likely have a better playback experience in your presentation?
    8·2 answers
  • Help me on this question
    14·1 answer
  • How do you get free Wifi on your phone without paying
    6·1 answer
  • True or false.local and cloud backup differs in where the backup is saved
    15·2 answers
  • 9.4 Code Practice: Your task is to determine whether each item in the array above is divisible
    14·1 answer
  • What is the definition of a nested function?
    8·1 answer
  • Which of the following statements best illustrates how value was created for eggs? when a farmer sells a chicken who is no longe
    9·1 answer
  • Who is famous for his three laws of robotics?
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!