Alex Rivera | Logout

How do I prevent Python's os.walk from walking across mount points?

Asked 2009-02-23T14:16:59.520
11

In Unix all disks are exposed as paths in the main filesystem, so os.walk('/') would traverse, for example, /media/cdrom as well as the primary hard disk, and that is undesirable for some applications.

How do I get an os.walk that stays on a single device?

Related:

Edit
Report

1 Answer

1

os.walk() can't tell (as far as I know) that it is browsing a different drive. You will need to check that yourself.

Try using os.stat(), or checking that the root variable from os.walk() is not /media

answered 2009-02-23T14:31:05.587

Your Answer