![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | path to item returned from get-childitem I'm having difficulty extracting the path to a file from the output of get-childitem. If I run "test.ps1" by entering .\test where test.ps1 contains: foreach ($childx in $(get-childitem "test" -recurse -filter "*.txt")) { echo("childx=" + $childx) echo ($childx) $child =resolve-path $childx echo ("child=" + $child) } with location set to a directory with a single .txt file, I get the following output: >> .\test childx=first.txt Directory: Microsoft.PowerShell.Core\FileSystem::C:\prof\computing\experimenting\P owerShell\test Mode LastWriteTime Length Name ---- ------------- ------ ---- -a--- 6/6/2007 4:57 PM 6 first.txt child= 80# as $child has a null value. How should I get the path? Thanks Mike |
My System Specs![]() |
| | #2 (permalink) |
| | Re: path to item returned from get-childitem "Mike Blake-Knox" <mikebk@nospam.nospam> wrote in message news:VA.000000af.22c42243@nospam.nospam... > I'm having difficulty extracting the path to a file from the output of > get-childitem. If I run "test.ps1" by entering .\test where test.ps1 > contains: > foreach ($childx in $(get-childitem "test" -recurse -filter "*.txt")) > { > echo("childx=" + $childx) > echo ($childx) > $child =resolve-path $childx > echo ("child=" + $child) > } Will this work for you? foreach ($childx in $(get-childitem "test" -recurse -filter "*.txt")) { echo("childx=" + $childx) echo ($childx) $child = $childx.fullname echo ("child=" + $child) } Essentially you would tend to use Resolve-Path on a string like .\*.txt but $childx is already a rich FileInfo *object* that contains lots of useful information like the path via the Fullname property. -- Keith |
My System Specs![]() |
| | #3 (permalink) |
| | Re: path to item returned from get-childitem Or are you just looking for the directory that the file is in? .... $child = $childx.directoryname .... -= IJuan =- "Keith Hill [MVP]" wrote: > "Mike Blake-Knox" <mikebk@nospam.nospam> wrote in message > news:VA.000000af.22c42243@nospam.nospam... > > I'm having difficulty extracting the path to a file from the output of > > get-childitem. If I run "test.ps1" by entering .\test where test.ps1 > > contains: > > foreach ($childx in $(get-childitem "test" -recurse -filter "*.txt")) > > { > > echo("childx=" + $childx) > > echo ($childx) > > $child =resolve-path $childx > > echo ("child=" + $child) > > } > > Will this work for you? > > foreach ($childx in $(get-childitem "test" -recurse -filter "*.txt")) > { > echo("childx=" + $childx) > echo ($childx) > $child = $childx.fullname > echo ("child=" + $child) > } > > Essentially you would tend to use Resolve-Path on a string like .\*.txt but > $childx is already a rich FileInfo *object* that contains lots of useful > information like the path via the Fullname property. > > -- > Keith > > |
My System Specs![]() |
| | #4 (permalink) |
| | Re: path to item returned from get-childitem In article <u90jsgRqHHA.4132@TK2MSFTNGP05.phx.gbl>, Keith Hill [MVP] wrote: > Essentially you would tend to use Resolve-Path on a string like .\*.txt but* > $childx is already a rich FileInfo *object* that contains lots of useful* > information like the path via the Fullname property. Thanks! I'd actually tried get-member to find which member to use but kept having a null return. I should have used the -inputObject parameter. |
My System Specs![]() |
| | #5 (permalink) |
| | Re: path to item returned from get-childitem On Jun 8, 7:15 am, Mike Blake-Knox <mik...@nospam.nospam> wrote: > In article <u90jsgRqHHA.4...@TK2MSFTNGP05.phx.gbl>, Keith Hill [MVP] wrote: > > Essentially you would tend to use Resolve-Path on a string like .\*.txt but > > $childx is already a rich FileInfo *object* that contains lots of useful > > information like the path via the Fullname property. > > Thanks! > > I'd actually tried get-member to find which member to use but kept having a > null return. I should have used the -inputObject parameter. You can also use: split-path $x -parent ~Josh |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Get-ChildItem Path Limitation | PowerShell | |||
| Get-ChildItem : Access to the path c:\asd is denied. | PowerShell | |||
| Counting items returned from Get-ChildItem.... | PowerShell | |||
| Get-ChildItem vs. Get-Item output | PowerShell | |||
| Inconsistent types returned from get-childitem | PowerShell | |||