Nathan McKaskle
Nathan McKaskle

Reputation: 3083

Error: does not contain a method named op_addition

I'm trying to remove everyone's Chrome cache directory with the following script but it keeps failing on this ridiculous error that makes no sense at all.

method invocation failed because system.io.directoryinfo does not contain a method named op_addition

Even when I just write the $loc to the console window I get the error. What am I doing wrong here?

$path = Get-ChildItem C:\Users\*\ | ?{ $_.PSIsContainer }
ForEach ($folder in $path) {
    $loc = $folder + "\AppData\Local\Google\Chrome\User Data\Default\Cache"
#   Remove-Item $loc
    Write-Host $loc
}

Upvotes: 0

Views: 3179

Answers (1)

4c74356b41
4c74356b41

Reputation: 72191

Because what you are trying to do is concatenate 2 string, but $folder is not a string. It's a system.io.directoryinfo object, do something like this instead:

$loc = $folder.FullName + "\AppData\Local\Google\Chrome\User Data\Default\Cache"

$Folder.Fullname returns a string and that can be concatenated.

Upvotes: 1

Related Questions