By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,824 Members | 1,255 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,824 IT Pros & Developers. It's quick & easy.

os.walk: Get entire path

P: n/a
Hello,
when I'm walking through a file system hierarchy using os.walk, how can I
get the full path of a file or dir? normpath and abspath don't work.
Thx,
Florian
Jul 18 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Florian Lindner schreef:
Hello,
when I'm walking through a file system hierarchy using os.walk, how can I
get the full path of a file or dir? normpath and abspath don't work.

Sure it does.

os.path.abspath(os.path.join(root, file_or_dir))

--
Peter Kleiweg L:NL,af,da,de,en,ia,nds,no,sv,(fr,it) S:NL,de,en,(da,ia)
info: http://www.let.rug.nl/~kleiweg/ls.html

Jul 18 '05 #2

P: n/a

"Florian Lindner" <Fl*************@xgm.de> wrote in message
news:cg*************@news.t-online.com...
Hello,
when I'm walking through a file system hierarchy using os.walk, how can I
get the full path of a file or dir? normpath and abspath don't work.
Thx,
Florian


I would use glob

import glob

glob.glob('c:\\images\\*\\*.jpg')

yields all .jpg's in //images and sub directories with full path in a list.

Tom
Jul 18 '05 #3

P: n/a
Tom B. wrote:
"Florian Lindner" <Fl*************@xgm.de> wrote in message
news:cg*************@news.t-online.com...
Hello,
when I'm walking through a file system hierarchy using os.walk, how can I
get the full path of a file or dir? normpath and abspath don't work.
Thx,
Florian

I would use glob

import glob

glob.glob('c:\\images\\*\\*.jpg')

yields all .jpg's in //images and sub directories with full path in a list.


No, it doesn't.

If the directory hierarchy is more thane one level deep you won't see
those files, and neither (I believe without verifying) will you see
files from the top-level directory itself.

regards
Steve
Jul 18 '05 #4

P: n/a
Hello Florian,
when I'm walking through a file system hierarchy using os.walk, how can I
get the full path of a file or dir? normpath and abspath don't work.

from os.path import join, abspath
from os import walk

for root, dirs, files in walk("somedir"):
for file in files:
print abspath(join(root, file))

HTH.
--
------------------------------------------------------------------------
Miki Tebeka <mi*********@zoran.com>
http://tebeka.spymac.net
The only difference between children and adults is the price of the toys
Jul 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.