I'm trying to check a series of directories and subdirectories to see if there are two or more files with the same name in the same folder. I think my issue is how I'm trying to validate a string.
For the following test directory:
- |-- C:\Test\
- |--C:\Test\YY\
- |--C:\Test\YY\xx.log
- |--C:\Test\YY\xx.txt
- |-- C:\Test\ZZ\
- |-- C:\Test\ZZ.log
- |-- C:\Test\ZZ.txt
- |--C:\Test\YY\
I need my code to find xx.log and ZZ.log. I can include a check against $_.PSisContainer (but I didn't think it was necessary).
ForEach ($item in (gci "C:\Test\*" -recurse)) {
If ($item.extension -notmatch "txt" -AND $item.basename+".txt" -eq $True) {
Write-Host $item.fullname
}
}
$item.basename+".txt" provides the right string but I can't use that string to validate the existence of the file.
Can anyone help correct my code? I'd like to learn how to handle concatenated strings like this--it's a trick I think would be useful in other areas.