Skip to content

Instantly share code, notes, and snippets.

@pylemon
Created July 17, 2012 02:20
Show Gist options
  • Save pylemon/3126578 to your computer and use it in GitHub Desktop.
Save pylemon/3126578 to your computer and use it in GitHub Desktop.
python: The pythonic way to walk through a file path
In [1]: import os
In [2]: dir = '/home/liwei/boxy'
In [3]: sum([[os.path.join(base,file) for file in files] for base,_,files in os.walk(dir)],[])
Out[3]:
['/home/liwei/boxy/test.html',
'/home/liwei/boxy/base.css',
'/home/liwei/boxy/jquery-1.6.4.min.js',
'/home/liwei/boxy/boxy.css',
'/home/liwei/boxy/boxy.zip',
'/home/liwei/boxy/jquery.boxy.js',
'/home/liwei/boxy/clear_boxy.css',
'/home/liwei/boxy/images/icon_close.gif',
'/home/liwei/boxy/images/pop_tbg.gif',
'/home/liwei/boxy/images/btn.gif',
'/home/liwei/boxy/bak/boxy_orig.css',
'/home/liwei/boxy/bak/screen.css']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment