This is a Go program that recursively searches for a file in a given directory and prints the found file path.
- Recursively searches through directories.
- Ignores
node_modules
andvendor
directories by default. - Uses Goroutines and channels for concurrency.
- Displays the time taken for the search.
- Gracefully stops when the file is found.
- Go 1.23.4 or later
- Clone the repository:
git clone https://github.com/kevariable/go-recursive-file-finder.git cd go-recursive-file-finder
- Build the program:
go build -o filefinder find.go
Run the program with the following command:
./filefinder -path "/your/search/path" -filename "target_file.txt" -ignores "node_modules, vendor"
-path
(default:.
) - The starting directory for the search.-filename
- The filename to search for.-ignores
(default:node_modules, vendor
) - Comma-separated list of directories to ignore.
./filefinder -path "/home/user/projects" -filename "config.json"
If config.json
is found, its full path is printed.
- The program initializes and parses flags.
- It executes the
ls
command to list directory contents. - It uses Goroutines and channels to efficiently traverse directories.
- When the target filename is found, it:
- Prints the full path.
- Stops further execution.
- The program displays the total execution time.
This project is open-source and available under the MIT License.