本文介绍了有没有办法在使用 os.walk 时确定子目录是否与 python 位于同一文件系统中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个 python 脚本,它使用 os.walk() 来遍历目录树.我想让它能够跳过挂载到不同文件系统的子目录,就像 find -xdev 那样.检查 os.walk() 上的文档,我没有看到任何参数可以通过它自动执行.有什么我可以用来自己做过滤的东西吗?希望在 Linux 和 Mac OS X 上运行的东西?

I'm writing a python script that uses os.walk() to walk a directory tree. I'd like to give it the ability to skip subdirectories that are mounted to a different file system, the way find -xdev does. Checking through the documentation on os.walk(), I didn't see any argument to pass in for it to do that automatically. Is there something I can use to do the filtering myself? Hopefully something that runs on both Linux and Mac OS X?

推荐答案

os.path.ismount()

这篇关于有没有办法在使用 os.walk 时确定子目录是否与 python 位于同一文件系统中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 20:58