I am looking for a code in python that allows me to take a directory and create a list similar to “ls –lR” containing all the files in the dir. and sub-dir. in a tabular form with their names, size, date last modified, permissions, users etc.
And also the total size of all the files in the directories and sub-directories.
I have used stats as of now, for the time, size and permissions and have appended the same in lists of which I have made tables. But to find the file name, the perm, owner and group. If I could get a neater code?
If you are using python 2.x you can use :
for python 3.0 you can try :
Hope it helps!
EDIT
Commands.getoutput and subprocess.check_output will return the output from the command you used as parameter.
Ex:
This will give you exactly the same output as ls -lR in your current dir. Then it’s up to you to filter whatever you need from there!
To change current dir use os.chdir(/desired/dir).