ブログを引っ越しました。-- Gray Sky, Blue Sea.
################################
2009-12-01
pythonでディレクトリのツリーマップ(樹形図)を作成。
pythonの練習に、cmdのtreeコマンド的な感じでフォルダの階層構成を表示するテストを書いてみたのです。
あまり美しくない感じになってしまった。
フローはこんな感じ↓
樹形図フロー
コード↓
import glob import os def tree(path, layer): files = glob.glob(path + '\\*') for file in files: # get dir or file path file_paths = file.split('\\') # get dir or file name print '\t' * layer + file_paths.pop() if os.path.isdir(file): # case dir (recall) tree(file, layer + 1) tree('C:\\Python26\\', 0)
トラックバック - http://d.hatena.ne.jp/enokitech/20091201/1259657213
リンク元
- 3 http://d.hatena.ne.jp/johzan/
- 3 http://d.hatena.ne.jp/johzan/20091202/1259686596
- 3 http://www.google.co.jp/search?sourceid=navclient&hl=ja&ie=UTF-8&rlz=1T4RNTN_jaJP353JP353&q=車の色と車内温度
- 2 http://d.hatena.ne.jp/johzan/searchdiary?word=*[Python]
- 2 http://reader.livedoor.com/reader/
- 2 http://www.google.co.jp/reader/view/
- 2 http://www.google.co.jp/search?hl=ja&client=firefox-a&rls=org.mozilla:ja:official&hs=j5o&q=55y9024+ドライバ&btnG=検索&lr=lang_ja&aq=f&oq=
- 1 http://d.hatena.ne.jp/enokitech
- 1 http://mail.google.com/mail/?ui=2&view=bsp&ver=1qygpcgurkovy
- 1 http://pink.s58.xrea.com/feedshowcat.php?c=c2fedc2