Python Query
Janko Hauser
jhauser at ifm.uni-kiel.de
Mon Mar 6 02:35:18 EST 2000
ns56645 <ns56645 at swt.edu> writes:
> Can anybody give me a code for the following in python:
>
> Program which does directory listing and everything that is a directory,
> the program puts the word "Directory" in front of it.
>
> The output should be as follows:
>
> a1.txt
> r1.bat
> k1 Directory
> a2.txt
> r2.txt
> k2 Directory
>
> because k1 and k2 are directories
>
### cut
import os
def list_content(dirname):
content=os.listdir(dirname)
for entry in content:
print entry,
if os.path.isdir(entry):
print '\t directory'
else:
print
if __name__ == '__main__':
list_content('./')
# HTH, __Janko
--
Institut fuer Meereskunde phone: 49-431-597 3989
Dept. Theoretical Oceanography fax : 49-431-565876
Duesternbrooker Weg 20 email: jhauser at ifm.uni-kiel.de
24105 Kiel, Germany
More information about the Python-list
mailing list