I am new to python and am working on writing bash ls
command in python, I am stuck on ls -a
option which (according to the manpage):
Include directory entries whose names begin with a dot (`.')
I am aware of os.listdir() but it does not list special entries '.' and '..'
From the docs: os.listdir(path):
Return a list containing the names of the entries in the directory given by path. The list is in arbitrary order. It does not include the special entries '.' and '..' even if they are present in the directory.
I need help in listing these special entries through python, I would appreciate if someone can help me out here a little.
Thanks all for your patience.
Just add them manually to os.listdir()
result. result = [os.curdir, os.pardir] + os.listdir(path)
.
Most modern filesystems no longer create the actual hardlinks but all APIs include the names explicitly anyway.
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