Skip to content

feat: Recusively scan folders [#120]#124

Open
JicLotus wants to merge 4 commits intoVirusTotal:masterfrom
JicLotus:josec/issue-120
Open

feat: Recusively scan folders [#120]#124
JicLotus wants to merge 4 commits intoVirusTotal:masterfrom
JicLotus:josec/issue-120

Conversation

@JicLotus
Copy link

@JicLotus JicLotus commented Feb 15, 2026

Description

#120


Note on permissions: If recursion is disabled, the function behaves like the previous implementation and will only fail if the top-level directory is unreadable. With recursion enabled, permission errors can occur on subdirectories, as WalkDir attempts to access them.

Note on OS compatibility: We are using filepath.Clean and filepath.WalkDir, which are cross-platform aware, so depth calculation using strings.Split(path, string(os.PathSeparator)) should work on Windows/Unix.


This PR refactors NewFileDirReader to use Go’s standard filepath.WalkDir (here) for directory traversal, and avoid custom recursive implementations. The function efficiently reads all files under a directory, optionally traversing subdirectories up to a configurable maxDepth. Traversal is stopped immediately for directories beyond the allowed depth or when recursion is disabled using fs.SkipDir, avoiding unnecessary filesystem reads and reducing resource usage. This approach is safe, efficient, and reduces the risk of errors compared to manual recursion, while remaining idiomatic and easy to maintain.

Usage:

  • vt scan file YOUR_DIRECTORY (default recursive disabled + maxDepth == 1)
  • vt scan file YOUR_DIRECTORY -r (recursive enabled with default maxDepth == 1)
  • vt scan file YOUR_DIRECTORY -r -d 3 (recursive enabled + setting up maxDepth to read more subtrees until reaching depth == 3 on each subdirectory)

Testing

  1. Unit testing: Added comprehensive unit tests covering scenarios with recursion enabled and disabled, as well as multiple depth levels, both with and without subdirectories.

  2. Manual build testing(mac-os). Successfully built+installed the binary and verified normal usage. Note we scanning multiple directories now

image
  1. Compiled in all architectures make all
image
  1. Windows tests. Everything runs as expected, you can see scanning files from multiple directories
image

@JicLotus JicLotus marked this pull request as ready for review February 15, 2026 15:41
@JicLotus JicLotus changed the title feat: Recusively scan folders [WIP][#120] feat: Recusively scan folders [#120] Feb 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant