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
A goal should be___.
Luda [366]

Answer:

D

Explanation:

5 0
3 years ago
Read 2 more answers
Suppose you are provided with 2 strings to your program. Your task is to join the strings together so you get a single string wi
Mariulka [41]

Answer:

public class TestImport{

   public static void main(String[] args) {

       String string1 = args[1];

       String string2 = args[2];

       System.out.println(string1 +" " +string2);

   }

}

Explanation:

The solution here is to use string concatenation as has been used in this statement System.out.println(string1 +" " +string2);

When this code is run from the command line and passed atleast three command line arguments for index 0,1,2 respectively, the print statment will return the second string (that is index1) and the third argument(that is index2) with a space in-between the two string.

6 0
3 years ago
Determine if the situation below is a safe practice: Julia needs to hang some industrial shelvinv, so she carefully selects the
hichkok12 [17]
I think Julia did good.











Its safe 
7 0
3 years ago
Read 2 more answers
FILL IN THE BLANK
Gwar [14]

Answer:

search

Explanation:

4 0
3 years ago
Google is an example of a(n): Web site.search engine.search directory. subject directory
lora16 [44]
Google is famously known as a search engine and it is being used around the globe. Aside from being a search engine, it also offers other services such as productivity software or google docs, e-mail services like Gmail, cloud storage or the google drive and it also offers social networking services through google plus. Google also has some desktop application for free of use such as google chrome, picasa and instant messaging like hangouts. Their mission statement as for being the most used search engine is "to organize the world's information and make it universally accessible and useful".
6 0
3 years ago
Other questions:
  • Use ________ resolution when recording human speech in an audio file.
    14·1 answer
  • Please helpp!! I need it quickly!
    6·1 answer
  • What provides quality education for students
    14·1 answer
  • Write the definition of a method dashedLine, with one parameter, an int. If the parameter is negative or zero, the method does n
    8·1 answer
  • WILL GIVE BRAINLIEST!!
    12·1 answer
  • Which part of project management involves determining the required materials?
    14·2 answers
  • What are the benefits of writing functions that use parameters and return? Try to list at least two.
    12·1 answer
  • 8.7 lesson practice question 1
    13·1 answer
  • How to connect apple pencil 2 to ipad 8th generation?
    11·1 answer
  • Complete the following sentences using each of the words provided ONCE only. KEYBOARD DESKTOP STORE PRINTER COMPUTER MOUSE MONIT
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!