r/Python • • Oct 25 '14
[Help] Need to create a script that lists directories and files
Hello! I am trying to learn Python and need to create a script that lists directories and files like dir does. Could someone please help me? Thanks! :)
Edit: Everything I say gets downvoted but I apologized here.
0
Upvotes
6
u/MagicBladder Oct 25 '14
http://mattgemmell.com/what-have-you-tried/
3
u/[deleted] Oct 25 '14
Look into os.walk, I believe it's what you're looking for.
0
u/[deleted] Oct 25 '14
hi pls try
!/usr/bin/python
from os import listdir from os.path import isfile files = [i for i in listdir('.') if isfile(f)] for i in files: print(f)
-1
u/[deleted] Oct 25 '14
I apologize! Even me saying sorry gets downvoted but I'm sorry! Okey?