similar to this command" dir test.txt /s /p
check multiple files in folder and subfolders
Clinton van Axel
126
Reputation points
Hi all,
Is it possible to check for multiple files in folders and subfolders.
After the check do a copy.
I already made the copy part.
Get-Childitem "C:\Temp\*" -Include "test3.txt","test8.txt","test1.txt","test9.txt" -Recurse | foreach-object{Copy-Item -Path $_ -Destination "Q:\" -PassThru -recurse -Force}
I need help with the if part and how to use the test-path.
Windows for business | Windows Server | User experience | PowerShell
7 answers
Sort by: Most helpful
-
-
Andreas Baumgarten 129.5K Reputation points MVP Volunteer Moderator2022-07-14T19:24:41.54+00:00 Hi @Siu Yip ,
here we go:
$filename = "2.txt" $rootfolder = "./Junk" Get-ChildItem -Path $rootfolder -Directory -Recurse | ForEach-Object { Write-Host "Checking folder $($_.FullName) for $filename" -ForegroundColor Yellow if (Test-Path -Path "$($_.Fullname)/$filename" -PathType Leaf) { Write-Host "File $filename exists in $($_.FullName)" -ForegroundColor Red } else { Write-Host "File $filename does not exist in $($_.FullName)" -ForegroundColor Blue } }----------
(If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)
Regards
Andreas Baumgarten