Search files on specific depth level

This topic contains 2 replies, has 2 voices, and was last updated by  Manuel Gonzalez Anido 4 years, 4 months ago.

  • Author
  • #14023

    How can I search for a file in a specific subfolder that constantly changes name. Max depth should be at -1. My current script is:

    $FilePathStat = "C:\NG_auto_project\nextgene_to_import"
    $FileNameStat = "*_StatInfo.txt"
    $Outputa = Get-ChildItem -Path $FilePathStat -Filter $FileNameStat | select -ExpandProperty FullName

    Can you pliz help me?


  • #14024

    Dave Wyatt

    I'm not sure I fully understand the question. However, there's a neat trick with PowerShell and Get-ChildItem that allows you to search at a specific depth using wildcards:

    Get-ChildItem -Path 'RootFolder\*\*\*'

    This will return all items that are nested two levels deep beneath RootFolder, for example, "RootFolder\SubFolder1\SubFolder2\file.txt", etc. This is much shorter than writing a recursive function yourself.

  • #14025

    Sorry then if I was not clear. All the files I need to search for are 1 level deeper than C:\NG_auto_project\nextgene_to_import.
    I guess I only need to put C:\NG_auto_project\nextgene_to_import\*\*\ .

    I completely forgot that one.


You must be logged in to reply to this topic.