Question

Can you write a Python 2.7 function that takes a directory path, and prints the size,...

Can you write a Python 2.7 function that takes a directory path, and prints the size, in bytes, of all the files, ignoring sub-directories, reverse sorted by size, with the total in the following exact format:

file_name_2: 200000
file_name_1: 100000
file_name_3: 1000

> 3 File(s) - Total: 301000.

Provide the copyable code.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

import or hich cootcins e y #filer #Gettist-of-file! Elle-list-os, listdir (direct or y ) list-paine s [] #add file, to list

Add a comment
Know the answer?
Add Answer to:
Can you write a Python 2.7 function that takes a directory path, and prints the size,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • This script will create a dictionary whose keys are all the directories listed in thePATH system...

    This script will create a dictionary whose keys are all the directories listed in thePATH system variable, and whose values are the number of files in each of these directories. The script will also print each directory entry sorted by directory name. The script will use the following five functions to get the required results get_environment_variable_value() get_dirs_from_path() get_file_count() get_file_count_for_dir_list() print_sorted_dictionary() get_environment_variable_value() The header for this function must be This function must accept a shell variable as its only parameter The...

  • #PYTHON# In this exercise you will write code which loads a collection of images (which are...

    #PYTHON# In this exercise you will write code which loads a collection of images (which are all the same size), computes a pixelwise average of the images, and displays the resulting average. The images below give some examples that were generated by averaging "100 unique commemorative photographs culled from the internet" by Jason Salavon. Your program will do something similar. Write a function in the cell below that loads in one of the sets of images and computes their average....

  • IT PYTHON QUESTION1 Consider the following Python code, where infile.txt and outfile.txt both exist in the current directory 'z' ) 。1d = open ( ' infile. txt ' , for line in o...

    IT PYTHON QUESTION1 Consider the following Python code, where infile.txt and outfile.txt both exist in the current directory 'z' ) 。1d = open ( ' infile. txt ' , for line in old: new.write (line) new.write') ne«.close () old.close) Which of the following options best describes the purpose or outcome of this code? O A copy of the file infile.txt is made (except in double line spacing) and saved as outfile.txt in the current directory. O A copy of the...

  • i need help with this scripting assignment in power shell thanks Lab 7: PowerShell Search and...

    i need help with this scripting assignment in power shell thanks Lab 7: PowerShell Search and Report Search Report host path date Execution time nnn Directories n, nnn, nnn Files nnnnnnn Sym links nnnnnnn Old files nnnnnnn Large files nnnn, nnn Graphics files nnnnnnn Executable files nnnnnnn Temporary files n, nnn, nnn TotalFileSize nnnn, nnn Introduction Lab 7 is nearly identical to Lab 2, except it is written in PowerShell, uses no UNIX/Linux tools to do its work, creates no...

  • Task 1: Write a Python program that takes as input from the user the name of a file containing po...

    python code: Task 1: Write a Python program that takes as input from the user the name of a file containing postcode/location information. Each line in the file consists of the postcode followed by a tab followed by a comma-separated list of locations that have that postcode. For example, the file Small.txt contains: 3015 Newport,South Kingsville,Spotswood 3016 Williamstown 3018 Altona,Seaholme 3019 3021 Albanvale,Kealba,Kings Park,St Albans Braybrook, Robinson Your program should create a list of postcode/location pairs with each pair stored...

  • i need python code, thank you very much! characters) and prints ) 3. Write function, smallestCharacterLargerThan(keyChar,...

    i need python code, thank you very much! characters) and prints ) 3. Write function, smallestCharacterLargerThan(keyChar, inputString) that takes as input key character, keyChar, and a string of one or more letters (and no other the "smallest" character in the string that is larger than keyChar, where one character is smaller than another if it occurs earlier in the alphabet (thus 'C is smaller than 'y' and both are larger than 'B') and 2) the index of the final occurrence...

  • Python Project

    AssignmentBitmap files map three 8-bit (1-byte) color channels per pixel. A pixel is a light-emitting "dot" on your screen. Whenever you buy a new monitor, you will see the pixel configuration by its width and height, such as 1920 x 1080 (1080p) or 3840x2160 (4K). This tells us that we have 1080 rows (height), and each row has 1920 (width) pixels.The bitmap file format is fairly straight forward where we tell the file what our width and height are. When...

  • 1 Overview The goal of this assignment is to help you understand caches better. You are...

    1 Overview The goal of this assignment is to help you understand caches better. You are required to write a cache simulator using the C programming language. The programs have to run on iLab machines. We are providing real program memory traces as input to your cache simulator. The format and structure of the memory traces are described below. We will not give you improperly formatted files. You can assume all your input files will be in proper format as...

  • Implement the histogram function to complete the desired program. You must use dynamically allocated arrays for...

    Implement the histogram function to complete the desired program. You must use dynamically allocated arrays for this purpose. For your initial implementation, use ordered insertion to keep the words in order and ordered sequential search when looking for words. Note that the array utility functions from the lecture notes are available to you as art of the provided code. Although we are counting words in this program, the general pattern of counting occurrences of things is a common analysis step...

  • You need not run Python programs on a computer in solving the following problems. Place your...

    You need not run Python programs on a computer in solving the following problems. Place your answers into separate "text" files using the names indicated on each problem. Please create your text files using the same text editor that you use for your .py files. Answer submitted in another file format such as .doc, .pages, .rtf, or.pdf will lose least one point per problem! [1] 3 points Use file math.txt What is the precise output from the following code? bar...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT