我想找到一个名称从当前目录递归启动的目录,并获得它的绝对路径。我不知道哪个目录包含我需要的东西。所以我必须检查每个上层目录是否包含我需要的内容。
例如,我有这样的目录树:
.
├── root
├── ...
├── someDir000
│ └── ...
│ └── someDir001
│ ├── otherDir000
│ └── dirPathIWantToFind
│ └── ...
├── someDir002
│ ├── anotherDir000
│ └── anotherDir001
│ ├── myCurrentDir
我目前在myCurrentDir中,想为**dirPathIWantToFind**找到一个路径,所以它应该是/root/someDir000/someDir001/dirPathIWantToFind
。
我知道可以递归地从当前目录向下倾斜,但如何向上倾斜呢?
Dir.glob(Pathname('/root').join('**/**/dirPathIWantToFind'))
请参阅Dir.glob。不过请注意,根据文件系统的大小,这可能需要相当长的时间。