Just started with learning python and tried something, most people here would call more than simple.
I just wanted to list all directories within my main directory. So I user the following code:
#!/usr/bin/env python
import os
if os.path.isdir("/home/testaccaunt/public_html"):
print "I am a directory"
else:
print "I am NO directory"
So that is just a first test for me and the result is always that my public_html folder is no directory. I also tested it with os.path.isfile and os.path.islink and it alway tells me that it is something different.
Hopefully you have an idea on that. It is on CentOs 5.
As a found it at nearly every beginner guide, with the os.listdir option I am listing all files and folders within my directory and the os.path.isdir is used to find out that one is a file or a directory.
So I just the tried the following piece of code:
#!/usr/bin/env python
import os
filelist = os.listdir("/home")
for file in filelist:
if os.path.isdir(file):
print "I am a directory"
else:
print "I am NO directory"
If I just remove the if, I am able to print all files and directories, but that tiny if clause is just not working. Any idea where my fault is?