Answered step by step
Verified Expert Solution
Question
1 Approved Answer
``` import sys import os from os import listdir from os.path import isfile, join from os.path import isdir from pathlib import Path def list ()
```
import sys import os from os import listdir from os.path import isfile, join from os.path import isdir from pathlib import Path def list(): # list of the content of every chosen directory for i in os.listdir(r'C:\Test\\'): # os.listdir will help us to list the content of the respective dir print(i) dir = input("Choose a directory to list its content: ") if Path('C:\\Test\\' + dir).is_dir(): # checks if the directory exists # print("Directory exist") for i in os.listdir('C:\\Test\\' + dir): # we concatenate the previous dir to the chosen directory in order to list the content of that directory print(" " + i) print(" The above is the content of the directory " + dir) else: print("Directory does not exist!") if __name__ == '__main__': list()
```
I would like to print the information in a table sorted into directory, subdirectory and files (if permits)....
Please if anyone could help me!!!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started