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
The most effective technique of malware propagation among the following list
iVinArrow [24]

Question Completion with Options:

A. Embedding & packing malcode in application programs

B. Replacing the Import-Address-Table (IAT)

C. Appending & prepending malcode into application programs

D. Embedding malcode in documents, such as MS O Office & PDF

Ε. Replicating malcode's source code

Answer:

The most effective technique of malware propagation among the following list is:

A. Embedding & packing malcode in application program

Explanation:

Malware propagation becomes effective and replicates effortlessly when malicious codes (otherwise called malcodes, which are self-replicating malicious programs) are embedded and packed in application programs.  These usually take many years before they start to manifest, making them very difficult to detect.  They are often triggered by some set events.  Given the nature of malcodes and the culprits behind them, they are very dangerous to applications and pose substantial business risks.

6 0
3 years ago
Write a function called median, that takes as parameter a full, sorted array of doubles and returns the median of the list. For
trapecia [35]

Answer:

Explanation:

public class Lab8

{

public static double median(double list[])

{

int size=list.length;

if(size%2!=0)

return list[size/2];

else

return(list[size/2-1]+list[size/2])/2.0;

}

public static boolean issorted(double list[])

{

for(int i=0;i<list.length-1;i++)

{

if(list[i]>list[i+1])

return false;

}

return true;

}

public static void findcommon(int a1[],int a2[],int common[])

{

int c=0;

for(int i=0;i<a1.length;i++)

{

boolean isFilled=false;

for(int j=0;j<c;j++)

{

if(a1[i]==common[j])

{

isFilled=true;

break;

}

}

if(isFilled)

{

for(int k=0;k<a2.length;k++)

{

if(a1[i]==a2[i])

{

common[c]=a1[i];

c++;

break;

}

}

}

}

while(c<common.length)

{

common[c]=0;

c++;

}

}

public static void rotateRight(int list[])

{

int temp=list[list.length-1];

for(int i=list.length-1;i>0;i--)

{

list[i]=list[i-1];

}

list[0]=temp;

}

public static int count(int list[],int n)

{

int ncount=0;

for(int i=0;i<list.length;i++)

{

if(list[i]==n)

ncount++;

}

return ncount;

}

public static int[] stretch(int list[])

{

int stretchedList[]=new int[list.length*2];

int k=0;

for(int i=0;i<list.length;i++)

{

int n=list[i];

if(n%2==0)

{

stretchedList[k]=n/2+1;

stretchedList[k+1]=n/2;

}

k+=2;

}

return stretchedList;

}

public static void printDoubleArray(double arr[])

{

System.out.print("[");

for(int i=0;i<arr.length;i++)

{

if(i!=arr.length-1)

System.out.print(arr[i]+",");

else

System.out.print(arr[i]);

}

System.out.println("]");

}

public static void printIntArray(int arr[])

{

System.out.print("[");

for(int i=0;i<arr.length;i++)

{

if(i!=arr.length-1)

System.out.print(arr[i]+",");

else

System.out.print(arr[i]);

}

System.out.println("]");

}

public static void main(String[] args)

{

double list1[]={1.1,2.2,3.3,4.4,5.5,6.6};

double med=median(list1);

System.out.println("List1:");

printDoubleArray(list1);

System.out.println("Median of List1:"+ med);

double list2[]={1.1,2.2,3.3,4.4,6.6,5.5};

boolean result=issorted(list2);

System.out.println("List2:");

printDoubleArray(list2);

System.out.println("List2 is a sorted array.(T/F):"+ result);

int list3[]={3,8,5,6,5,8,9,2};

int list4[]={5,15,4,6,7,3,9,11,9,3,12,13,14,9,5,3,13};

int list5[]=null;

if(list3.length<=list4.length)

list5=new int[list3.length];

else

list5=new int[list4.length];

findcommon(list3,list4,list5);

System.out.println("\n List3:");

printIntArray(list3);

System.out.println("\n List4:");

printIntArray(list4);

System.out.println("\n Array with common value,List5:");

printIntArray(list5);

int list6[]={3,8,19,7};

System.out.println("\n List6:");

printIntArray(list6);

rotateRight(list6);

System.out.println("\n the array after rotate right:");

printIntArray(list6);

int list7[]={3,5,2,1,92,38,3,14,5,73};

int n=count(list7,3);

System.out.println("\n List7:");

printIntArray(list7);

System.out.println("\n the number of occurences of the value 3 in the list 7:"+ n);

int list8[]={18,7,4,24,11};

int list9[]=stretch(list8);

printIntArray(list8);

System.out.println("\n The array after stretching:");

printIntArray(list9);

}

}

8 0
3 years ago
This question involves the creation of user names for an online system. A user name is created based on a user’s first and last
Evgen [1.6K]

Answer:

See explaination

Explanation:

import java.util.*;

class UserName{

ArrayList<String> possibleNames;

UserName(String firstName, String lastName){

if(this.isValidName(firstName) && this.isValidName(lastName)){

possibleNames = new ArrayList<String>();

for(int i=1;i<firstName.length()+1;i++){

possibleNames.add(lastName+firstName.substring(0,i));

}

}else{

System.out.println("firstName and lastName must contain letters only.");

}

}

public boolean isUsed(String name, String[] arr){

for(int i=0;i<arr.length;i++){

if(name.equals(arr[i]))

return true;

}

return false;

}

public void setAvailableUserNames(String[] usedNames){

String[] names = new String[this.possibleNames.size()];

names = this.possibleNames.toArray(names);

for(int i=0;i<usedNames.length;i++){

if(isUsed(usedNames[i],names)){

int index = this.possibleNames.indexOf(usedNames[i]);

this.possibleNames.remove(index);

names = new String[this.possibleNames.size()];

names = this.possibleNames.toArray(names);

}

}

}

public boolean isValidName(String str){

if(str.length()==0) return false;

for(int i=0;i<str.length();i++){

if(str.charAt(i)<'a'||str.charAt(i)>'z' && (str.charAt(i)<'A' || str.charAt(i)>'Z'))

return false;

}

return true;

}

public static void main(String[] args) {

UserName person1 = new UserName("john","smith");

System.out.println(person1.possibleNames);

String[] used = {"harta","hartm","harty"};

UserName person2 = new UserName("mary","hart");

System.out.println("possibleNames before removing: "+person2.possibleNames);

person2.setAvailableUserNames(used);

System.out.println("possibleNames after removing: "+person2.possibleNames);

}

}

8 0
3 years ago
Your employer gives you a list of all chemicals in the entire building and the location of the SDS collection, and he asks you t
stepladder [879]
Employers should familiarize themselves with the training requirements that apply to their employees and their business; design and implement effective training programs; and use qualified trainers. In addition, employers should thoroughly document all training activities, and should retain records of employee attendance at all completed trainings. Training records should include the name of the trained employee, the date of training, the type of training and the training provider. It is a best practice for employers to keep documentation of all trainings provided to demonstrate compliance with all applicable laws and regulations.
4 0
3 years ago
Read 2 more answers
When creating a presentation you should use a blank as a starting point?
Lera25 [3.4K]
A blank presentation is recommended as the starting point when creating a PowerPoint presentation.  PowerPoint <span>lets you change the appearance, layout and content of your presentation at any time. Starting with a blank presentation lets you experiment more easily with the many features this program offers.</span>
6 0
3 years ago
Other questions:
  • How can you clean out the scales in an electric iron without taking the iron apart? A. By rinsing the tank and holes with a wate
    12·2 answers
  • HELP ASAP U GET BRAINLIEST
    15·2 answers
  • Cyberlaw consists of: a. only state statutes. b. only federal statutes. c. traditional legal principles that have changed becaus
    6·1 answer
  • Write a Temperature class that will hold a temperature in Fahrenheit and provide methodsto get the temperature in Fahrenheit, Ce
    14·1 answer
  • Most 4 year colleges want an applicant's scores for all the following except
    12·1 answer
  • B. What significant values have you learned while learning the tools and utensils?
    8·1 answer
  • Can someone find out what this binary number thing is. Just find out the message, I'm having a difficult time
    13·1 answer
  • How does the autosum command calculate data? Need help ASAP​
    5·1 answer
  • The underlying color of a slide.
    9·1 answer
  • Discuss the advantages and disadvantages of supporting links to files that cross mount points (that is, the file link refers to
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!