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
Analyze the following code.
denis-greek [22]

Answer:

C

Explanation:

No explanation, self-explanatory. I used class main instead...

4 0
3 years ago
Some jobs have a greater risk of workplace violence. Which of the following are factors that lead to an increased risk of workpl
Aliun [14]
Im not sure about B.  but if you can choose mutiple pick C,D,E  but if you can shoose only one than pick A 
3 0
3 years ago
The undo function allows the user to cancel up to _____ previous typing actions.
GalinKa [24]
C 20 previous typing actions
4 0
3 years ago
David was editing his audio recording in his audio editing software. He adjusted the vocal track of his audio toward
Dmitrij [34]

Answer:

b

Explanation:

balancing the sound

a                h    o

l                 e    u

a                      n

n                      d

c

i

n

g

6 0
2 years ago
Write a loop that sets new scores to old scores shifted once left, with element 0 copied to the end. ex: if old scores = {10, 20
Inga [223]

#include <iostream>
using namespace std;

int main() {
   const int SCORES_SIZE = 4;
   int oldScores[SCORES_SIZE];
   int newScores[SCORES_SIZE];
   int i = 0;

   oldScores[0] = 10;
   oldScores[1] = 20;
   oldScores[2] = 30;
   oldScores[3] = 40;

   /* Your solution goes here */

   for (i = 0; i < SCORES_SIZE; ++i) {
      cout << newScores[i] <<" ";
   }
   cout << endl;

   return 0;
}

3 0
2 years ago
Read 2 more answers
Other questions:
  • A half-life is the amount of time it takes for a substance or entity to fall to half its original value. Caffeine has a half-lif
    10·1 answer
  • What is heaven backwards?
    11·2 answers
  • _________ are represented using diamonds linked withparticipant ETs
    6·1 answer
  • Windows 1.0 was not considered to be a "true" operating system but rather an operating environment because _____.
    13·1 answer
  • Which of the following is considered a modern method of communication?
    7·2 answers
  • Given an array arr, of type int, along with two int variables i and j, write some code that swaps the values of arr[i] and arr[j
    11·1 answer
  • Two employees were very different in terms of​ age, gender, and other demographic data but they shared a common love of dogs and
    8·1 answer
  • When working in Photoshop with the move tool, you can select multiple layers and use this option to arrange them into a straight
    7·2 answers
  • Marco had a database that showed the first, second, and third favorite ice cream flavors for each person in his school. He used
    11·2 answers
  • Convert octal number 2470 to decimal number
    14·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!