Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SHELL

powershell read a list of names frmo a file and red in FOR loop

$Dir2 = 'C:UsersAdministratorDesktop	estDir2'
$filenames=Get-Content $Dir2filenamesnoext.csv
foreach ($filename in $filenames) {
$found=$false; 
Get-ChildItem -Path $Dir2 -Recurse | ForEach-Object {if($filename -eq $_.BaseName) {Write-Host 'FILE ' $filename ' Ok' -foregroundcolor green; $found=$true;CONTINUE }$found=$false;} -END {if($found -ne $true){ Write-Host 'FILE ' $filename ' missing in the folder' -foregroundcolor red}}
}
Get-ChildItem -Path $Dir2 -Recurse | ForEach-Object  {$found=$false; foreach ($filename in $filenames) {if($filename -eq $_.BaseName) {Write-Host 'FILE ' $_.BaseName ' was found on the list' -foregroundcolor cyan; $found=$true;BREAK }} if($found -ne $true){ Write-Host 'FILE ' $_.BaseName ' missing on the list of files' -foregroundcolor Magenta} }
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #powershell #read #list #names #frmo #file #red #FOR #loop
ADD COMMENT
Topic
Name
7+1 =