I have a list of file names stored in a text file I would like to search a particular directory and subdirectories and get the full path of all the the files that exist.
Right now I'm using the below code
$FileListPath = "C:\FileList.txt"
$SearchPath = "Y:\Project"
foreach($FileName in Get-Content $FileListPath){(Get-ChildItem -Path $SearchPath -Recurse -ErrorAction SilentlyContinue -Include $FileName).FullName}
This works OK but is slow. I think because for each file it's doing the full search again and again. Is there a faster way to do this?
Also, it's not strictly necessary but I would like to exclude subfolders that have that have include obj as one of the folders. For example: Y:\folder\ I want to be included but y:\Folder\obj\ and Y:\Folder\obj\subfolder I want to be excluded.
Thanks