I have two below arrays in powershell $obj= ('Sales','Finance','config.ini') $objPath= ('D:\Project','D:\Element','D:\Project')
- now $obj can be a folder name or a file name
- $objPath is the path where the respective positional $obj will reside
I want to check if that folder or file exist in the respective $objPath
my code:
foreach($element in $obj){
foreach($elementpath in $objPath){
Test-Path $element+'\'+$elementpath
}
}
But it is returning false everytime. Can anyone please suggest where I am doing wrong
$element+'\'+$elementpath? What are you trying to do? Single-quotes'prevent variable expansion so if you want to check$element+\$elementpathuse double quotes like"$element+\$elementpath".