# $cs.File_FindFile

> Searches for files matching a name or wildcard pattern starting at searchroot, and returns the full paths of every match.

Source: https://docs.capaone.com/capainstaller/powerpacks/cs-file-findfile/  
Product: CapaInstaller — a separate CapaSystems product; do not apply this page to any other.

### Description

Searches for files matching a name or wildcard pattern starting at `searchroot`, and returns the full paths of every match. Throws `ArgumentNullException` if `filename` is empty, and `DirectoryNotFoundException` if `searchroot` doesn't exist.

### Syntax

$cs.File_FindFile(string filename, string searchroot, bool recursive)

### Parameters

#### filename (String)

Name or wildcard pattern of the file(s) to search for, e.g. `"*.log"`.

#### searchroot (String)

Directory to start the search from. Must exist.

#### recursive (Boolean)

`$true` to search `searchroot` and every subfolder beneath it; `$false` to search only `searchroot` itself.

### Return value

A list of strings containing the full path of every matching file. Returns an empty list (not `$null`) if nothing is found.

### Example

**PowerShell**

```powershell
$searchRoot = "C:\Users"
if ($cs.File_ExistDir($searchRoot))
{
  $updateFiles = $cs.File_FindFile("update.exe", $searchRoot, $true)
  $cs.Job_WriteLog("Found $($updateFiles.Count) matching file(s)")
}
```

Recursively search a data folder tree for a specific log file left behind by the vendor installer:

```powershell
$dataRoot = Join-Path $env:ProgramData "Contoso"
if ($cs.File_ExistDir($dataRoot))
{
  $matches = $cs.File_FindFile("setup.log", $dataRoot, $true)
  foreach ($match in $matches)
  {
    $cs.Job_WriteLog("Found setup log at $match")
  }
}
```

Restrict the search to just the kit's top folder (non-recursive) to locate the bundled MSI without descending into subfolders:

```powershell
$kitRoot = Join-Path $global:Packageroot "kit"
$msiFiles = $cs.File_FindFile("*.msi", $kitRoot, $false)
if ($msiFiles.Count -eq 0)
{
  Exit-PSScript -exitcode 1 -exitmessage "No MSI found directly under $kitRoot, aborting"
}
```

### Related functions

[$cs.File_ExistFile](/capainstaller/powerpacks/cs-file-existfile/) [$cs.File_ExistDir](/capainstaller/powerpacks/cs-file-existdir/)
