Reputation: 755
I am trying to list all folders of a directory using python in Mac os 10.8.2.
My code is as simple as this:
#!/usr/bin/env python
#coding: utf8
import os
print [name for name in os.listdir(os.path.abspath('.')) if os.path.isdir(name)]
When I run this script in a path where there are folders the outcome is:
[]
I try this same script in another computer (ubuntu) and it works perfectly, listing all the directories in the current path.
I have tried exactly the same in the python console in that path and it works, the outcome is:
['Final', 'Script_actualizacion', 'Z_L1']
What could be happening?
Upvotes: 1
Views: 3014
Reputation: 755
Ok now this is working:
#!/usr/bin/env python
#coding: utf8
import os
path = os.path.abspath('.')
print [name for name in os.listdir(path) if os.path.isdir(os.path.join(path,name))]
The problem happened because I was calling the python from a different location so it checked the dirs in the wrong path.
Upvotes: 2