Author Posts

March 24, 2014 at 3:16 am

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?

THX

March 24, 2014 at 3:22 am

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.

March 24, 2014 at 3:53 am

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.

THX