#search #logging #file-path #io #utilities #filesize #cli

bin+lib sizer

此工具在指定的目录中查找大于100MB的文件,如果没有给出文件路径,则在整个文件系统中查找。

1个不稳定版本

0.1.0 2023年10月17日

#46 in #filesize

MIT 许可证

20KB
307 代码行

摘要

此代码实现了一个Rust程序,该程序在指定的目录中查找大于100MB的文件,如果没有给出文件路径,则在整个文件系统中查找。它使用clap库进行命令行参数解析,并使用std库进行文件大小计算。

使用示例

// Run the program with a specific directory path
$ ./sizer -p /path/to/directory

// Run the program without specifying a directory path (searches the whole file system)
$ ./sizer

// Run the program with a specific directory path and custom file size threshold
$ ./sizer -p /path/to/directory -s 200

代码分析

输入

  • matches:一个包含解析后的命令行参数的clap::ArgMatches对象。

流程

  1. 初始化日志记录器以进行日志记录。
  2. 使用clap解析命令行参数以获取matches对象。
  3. matches对象中获取path参数的值。
  4. 如果提供了path值,将其转换为PathBuf对象,并将其分配给home_dir
  5. matches对象中获取size参数的值。
  6. 如果提供了size值,将其作为Option<&String>分配给size
  7. 如果提供了path值,使用home_dirsize作为参数调用sizer库中的entry函数。
  8. 如果没有提供path值,为根目录("/")创建一个PathBuf对象,并将其分配给root_dir
  9. 使用root_dirsize作为参数调用sizer库中的entry函数。

输出

无。该函数根据提供的命令行参数执行文件大小计算和日志记录。


依赖关系

~4–13MB
~146K SLoC