![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | 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 |
| | #2 (permalink) |
| Guest | 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 |
| | #3 (permalink) |
| Guest | 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 > > |
| | #4 (permalink) |
| Guest | 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. |
| | #5 (permalink) |
| Guest | 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 |
| |
| |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Get-ChildItem Path Limitation | Zac | PowerShell | 1 | 06-13-2007 07:59 PM |
| Get-ChildItem : Access to the path c:\asd is denied. | JMinahan | PowerShell | 1 | 03-08-2007 02:58 PM |
| Counting items returned from Get-ChildItem.... | fatboybubba | PowerShell | 2 | 03-05-2007 10:18 AM |
| Get-ChildItem vs. Get-Item output | Nick Howell | PowerShell | 1 | 01-06-2007 02:09 PM |
| Inconsistent types returned from get-childitem | Gary | PowerShell | 3 | 09-26-2006 09:41 AM |