Implement the functionality of the "find" command in UNIX as an API that returns a list of files matching the provided search parameters. The search should be limited to name and size only.
For example:
- Find all files that start with
"abc" - Find all files that are greater than or equal to
2MBin size
You can assume you are provided a File object with the following methods:
getName()– get the name of a file or directorygetSize()– get the size of a fileisDir()– checks whether the given path is a directory or a filelistFiles()– returns a list of files if initialized with a directory
这道题要求你把 UNIX 的 `find` 命令抽象成一个可调用的 API,输入一个目录或文件树,再根据文件名和文件大小进行筛选,返回所有满足条件的文件。核心思路通常是对目录树做递归遍历或使用栈进行深度 / 广度搜索:遇到目录就继续展开,遇到文件就检查它的名字前缀、大小是否满足条件。题目强调搜索条件只限定在名称和大小,因此实现时要把筛选逻辑和遍历逻辑分开,便于支持不同查询参数。
正文完