73.0k views
1 vote
Create a script that prompts for the user to input a directory and then prints out the number of sub-directories in the given directory, as well as the number of files (use the numbers only for the directory given, you do NOT need to do this recursively for all sub-directories).

User VilemRousi
by
6.6k points

1 Answer

1 vote

Answer:

Below is the required code:

Step-by-step explanation:

Python Code

import os

import bin

dir = input("Please specify the location to the directory")

list = os.walk(dir)

a = length(list[1])

b = length(list[2])

print "Files: %n , Sub-dirs : %n" % (b,a)

decision = _(" Do you want to continue? (y/n) "))

if(decision):

cls

else :

exit()

User Albert Gao
by
7.0k points