Directory recursion

前端 未结 3 625
旧巷少年郎
旧巷少年郎 2021-01-03 09:08

If you need to recursively traverse a directory tree, there are two ways to do it:

  1. Build up pathnames of increasing length as you go, .../.../... etc.

相关标签:
3条回答
  • 2021-01-03 09:42

    Erm... in fact a modern implementation will likely use the

    • ftw
    • nftw calls

    ftw is short for file tree walk

    See also a very useful resource: http://rosettacode.org/wiki/Walk_a_directory/Recursively#Library:_POSIX

    0 讨论(0)
  • 2021-01-03 09:48

    The method 2 seemlessly handles situations where a component in the path is renamed.

    It also denies anyone from unmounting the directory while it's being searched; the kernel will refuse to unmount the directory if it's in use, which includes being the cwd of some process.

    0 讨论(0)
  • 2021-01-03 09:50

    I believe the find uses method 2 as you are able to execute commands as you go (with the exec option)

    0 讨论(0)
提交回复
热议问题