Powershell outputs Directory paths differently sometimes -


i'm using ls find directories convention. works in finds them, i'm piping results other functions. depending on way 'ls' (aka: dir) called. why happening?

c:\tmp40d4> ls *_pkg -recurse | %{"$_"} c:\tmp40d4\sub\a_pkg c:\tmp40d4\sub\b_pkg c:\tmp40d4\sub\c_pkg  c:\tmp40d4> ls sub *_pkg -recurse | %{"$_"} a_pkg b_pkg c_pkg 

both results list of directoryinfo instances.

c:\tmp40d4> ls sub *_pkg -recurse | %{$_.gettype()}  ispublic isserial name                                     basetype -------- -------- ----                                     -------- true     true     directoryinfo                            system.io.filesysteminfo true     true     directoryinfo                            system.io.filesysteminfo true     true     directoryinfo                            system.io.filesysteminfo 

as turns out, directoryinfo instances provided alternative calls ls result in different directoryinfo instances. specifically,

ls sub *_pkg -recurse | %{ [io.path]::ispathrooted($_) } result in

false false false 

while ls *_pkg -recurse | %{ [io.path]::ispathrooted($_) } result in

true true true 

it's important remember ls doesn't display anything. "$_" in %{ "$_" } shorthand write-host $_ equivalent write-host $_.tostring().

so turns out tostring() on non-rooted directoryinfo result in name, where-as tostring() on rooted use fullname.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -