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?
To traverse files recursively, you can use os.walk
. That will let you know all the file names that you need.
Once you have the file names, you can keep on using os.stat
to get the user and group ids. Regarding permissions, I think there isn't any way to get them directly using the standard library, but you can use os.access
to test permissions one by one to find out which ones are set.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With