Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

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.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

path to item returned from get-childitem

Closed Thread
 
Thread Tools Display Modes
Old 06-07-2007   #1 (permalink)
Mike Blake-Knox
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


Old 06-07-2007   #2 (permalink)
Keith Hill [MVP]
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

Old 06-07-2007   #3 (permalink)
IJuan
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
>
>

Old 06-08-2007   #4 (permalink)
Mike Blake-Knox
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.

Old 06-08-2007   #5 (permalink)
Josh
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

Closed Thread

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








Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50