powershell - What's wrong with my recursive delete? -
get-childitem -recurse | ? {$_.extension -eq ".obj" } | %{del $_} ~~~~~~ categoryinfo : objectnotfound: (c:\temp\compilerlimits\template.obj:string) [remove-item], itemnotfoundexception fullyqualifiederrorid : pathnotfound,microsoft.powershell.commands.removeitemcommand trying recursively delete .obj files; instead this.
try this:
get-childitem -recurse *.obj | remove-item in case of | %{del $_}, $_ system.io.fileinfo object , when powershell uses literalpath parameter, sees literalpath parameter takes string. conversion of fileinfo string seems use fileinfo.tostring() method in cases (like subdirs) doesn't include full path - filename. cause error seeing. when pipe in fileinfo object, pipeline argument binding rules used. literalpath parameter has alias called pspath. property added each fileinfo object powershell's type system. can see get-childitem *.obj | get-member. , since literalpath parameter has valuefrompipelinebypropertyname set true, powershell argument value object's pspath property.
you can read more in item 8 of effective powershell ebook.
Comments
Post a Comment