Developing a File System Crawler
Powerful Command-Line Applications in Go — by Ricardo Gerardi (40 / 127)
👈 Chapter 4 Navigating the File System | TOC | Testing with Table-Driven T esting 👉
The walk tool has two main goals: descending into a directory tree to look for files that match a specified criteria and executing an action on these files. Let’s start this tool by implementing the search and filter functionality. The only action we will implement now is listing the files. This enables us to try the tool and ensure it’s finding the correct files. You’ll implement other actions such as delete and archive later.
This initial version accepts four command-line parameters:
- -root: The root of the directory tree to start the search. The default is the current directory.
- -list: List files found by the tool. When specified, no other actions will be executed.
- -ext: File extension to search. When specified, the tool will only match files with this extension.
- -size: Minimum file size in bytes. When specified, the tool will only match files whose size is larger than this value.
Start by creating the directory fileSystem/walk for your new command-line tool in your book’s project directory:
$ mkdir -p $HOME/pragprog.com/rggo/fileSystem/walk
$ cd $HOME/pragprog.com/rggo/fileSystem/walk