Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a Python 2.7 function that takes a directory path, and prints the size, in

ID: 3706760 • Letter: W

Question

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
*Note please make sure the result of the code are reverse sorted by size and that the output matches the format specified above! 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
*Note please make sure the result of the code are reverse sorted by size and that the output matches the format specified above! 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
*Note please make sure the result of the code are reverse sorted by size and that the output matches the format specified above!

Explanation / Answer

Note:-

1.Python program follows indentation.

2.please modify the given program as see in the picture(Distance between left side should 100% accurate then

only your code works correctly)

Program

---------------------------------------------

import os
reallist=[]
def find_size(dire_path):
print("The following are the list of files in given directory ")
for path, dirs, files in os.walk(dire_path):
for filename in files:
print(filename)
for filename in files:
print(" ")
print("{0} has the size(in bytes)".format(filename))
filename = os.path.join(path, filename)
list=[]
list.append(os.path.getsize(filename))
for i in list:
print(i)
reallist.append(i)
print(" ")
print("After sorted reverse by size")
a=sorted(reallist, reverse=True)
for s in a:
print(s)
find_size("C:\Users\HP\Desktop\python")

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote