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

Another question about directories

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 03-10-2007   #1 (permalink)
Art
Guest


 

Another question about directories

Suppose I travel down a directory tree until I wind up with:
c:\documents and settings\Art\Math
I'd like to assign a variable to this path so I don't have to stay there. I
can type one in as "$a="c:\documents and settings\Art\Math". Is there a way
to capture or copy it so that I can assign my variable without the typing?


My System SpecsSystem Spec
Old 03-10-2007   #2 (permalink)
Brandon Shell
Guest


 

Re: Another question about directories

If you want just assign your current path to a var....
$a = $pwd # $pwd is a special variable that contains current path
will work.

"Art" <Art@discussions.microsoft.com> wrote in message
news:1259914D-06EB-47A9-ADB2-3FC083F6FE6E@microsoft.com...
> Suppose I travel down a directory tree until I wind up with:
> c:\documents and settings\Art\Math
> I'd like to assign a variable to this path so I don't have to stay there.
> I
> can type one in as "$a="c:\documents and settings\Art\Math". Is there a
> way
> to capture or copy it so that I can assign my variable without the typing?
>


My System SpecsSystem Spec
Old 03-10-2007   #3 (permalink)
Marty List
Guest


 

Re: Another question about directories


Hi Art,

Try:
$a=Get-Location
or use an alias:
$a=gl
$a=pwd

Also, see the Push-Location Pop-Location cmdlets:

Push-Location -?
Pop-Location -?

Or use an alias (pushd / popd)


"Art" <Art@discussions.microsoft.com> wrote in message
news:1259914D-06EB-47A9-ADB2-3FC083F6FE6E@microsoft.com...
> Suppose I travel down a directory tree until I wind up with:
> c:\documents and settings\Art\Math
> I'd like to assign a variable to this path so I don't have to stay there.
> I
> can type one in as "$a="c:\documents and settings\Art\Math". Is there a
> way
> to capture or copy it so that I can assign my variable without the typing?
>


My System SpecsSystem Spec
Old 03-11-2007   #4 (permalink)
Art
Guest


 

Re: Another question about directories

Brandon,

Thanks, it works. Although it raises a new question. When I set $a=$pwd,
and then type $a, I get a display that begins with "path" underscored and
then the string holding the path. Then, when I try dir $a, I get what I
want, but I'm confused as to why -- and also confused as to what's really in
$a at this point.

Can you tell me what's going on?



"Brandon Shell" wrote:

> If you want just assign your current path to a var....
> $a = $pwd # $pwd is a special variable that contains current path
> will work.
>
> "Art" <Art@discussions.microsoft.com> wrote in message
> news:1259914D-06EB-47A9-ADB2-3FC083F6FE6E@microsoft.com...
> > Suppose I travel down a directory tree until I wind up with:
> > c:\documents and settings\Art\Math
> > I'd like to assign a variable to this path so I don't have to stay there.
> > I
> > can type one in as "$a="c:\documents and settings\Art\Math". Is there a
> > way
> > to capture or copy it so that I can assign my variable without the typing?
> >

>
>

My System SpecsSystem Spec
Old 03-11-2007   #5 (permalink)
Art
Guest


 

Re: Another question about directories

Thanks Marty, it worked. Your answer raised a few questions. First is the
question about what's actually in $a -- I asked about that in my response to
Brandon. Your answer raised yet another question -- the stack. Is there a
way to manipulate this stack? For example, can I pop the stack into a
variable or push things other than the location onto the stack, or can I swap
the top elements or access something below the top of the stack?

I didn't know there was a stack, so this is very interesting.

"Marty List" wrote:

>
> Hi Art,
>
> Try:
> $a=Get-Location
> or use an alias:
> $a=gl
> $a=pwd
>
> Also, see the Push-Location Pop-Location cmdlets:
>
> Push-Location -?
> Pop-Location -?
>
> Or use an alias (pushd / popd)
>
>
> "Art" <Art@discussions.microsoft.com> wrote in message
> news:1259914D-06EB-47A9-ADB2-3FC083F6FE6E@microsoft.com...
> > Suppose I travel down a directory tree until I wind up with:
> > c:\documents and settings\Art\Math
> > I'd like to assign a variable to this path so I don't have to stay there.
> > I
> > can type one in as "$a="c:\documents and settings\Art\Math". Is there a
> > way
> > to capture or copy it so that I can assign my variable without the typing?
> >

>

My System SpecsSystem Spec
Old 03-11-2007   #6 (permalink)
Marty List
Guest


 

Re: Another question about directories


Any time you want to know what type of object is stored in a variable, use
|get-member or the variable's .GetType() method:

PS>$a=gl
PS>$a|gm
TypeName: System.Management.Automation.PathInfo
<snip>
PS>$a.GetType()

IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True False PathInfo System.Object

PS>$a.ToString()
D:\Tmp
PS>$a.Path
D:\Tmp
PS>$a.Path.GetType()

IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True String System.Object


I don't know if the stack can be manipulated, at first glance I don't see
anything about it:
get-help push-location -full


"Art" <Art@discussions.microsoft.com> wrote in message
news:157F44F1-AE75-4AC4-8550-C58BD0818398@microsoft.com...
> Thanks Marty, it worked. Your answer raised a few questions. First is
> the
> question about what's actually in $a -- I asked about that in my response
> to
> Brandon. Your answer raised yet another question -- the stack. Is there
> a
> way to manipulate this stack? For example, can I pop the stack into a
> variable or push things other than the location onto the stack, or can I
> swap
> the top elements or access something below the top of the stack?
>
> I didn't know there was a stack, so this is very interesting.
>
> "Marty List" wrote:
>
>>
>> Hi Art,
>>
>> Try:
>> $a=Get-Location
>> or use an alias:
>> $a=gl
>> $a=pwd
>>
>> Also, see the Push-Location Pop-Location cmdlets:
>>
>> Push-Location -?
>> Pop-Location -?
>>
>> Or use an alias (pushd / popd)
>>
>>
>> "Art" <Art@discussions.microsoft.com> wrote in message
>> news:1259914D-06EB-47A9-ADB2-3FC083F6FE6E@microsoft.com...
>> > Suppose I travel down a directory tree until I wind up with:
>> > c:\documents and settings\Art\Math
>> > I'd like to assign a variable to this path so I don't have to stay
>> > there.
>> > I
>> > can type one in as "$a="c:\documents and settings\Art\Math". Is there
>> > a
>> > way
>> > to capture or copy it so that I can assign my variable without the
>> > typing?
>> >

>>


My System SpecsSystem Spec
Old 03-11-2007   #7 (permalink)
Brandon Shell
Guest


 

Re: Another question about directories

One of the biggest conceptual changes to grasp is understanding that
powershell only deals with objects... Everything is an object. Its not like
Command Prompt, Bash, or Kshell.

In this case. When you do $a = $pwd you get a psinfo Oject that contains a
property called Path. I think it helps grasp this concept to do a get-member
(aliased to gm) and see what properties and methods an object has. The
sooner you can get away from the idea of passing text then better.

Some CMDLets that help here are
Get-help # To better understand what a command is doing and what it
returns
Get-Member # This will get you current members and properties availble
Get-Alias # I think it is best untiil you get comfortable with what is
going on in the background not to use short cuts. So try not to use alias.
i.e. dir ls gm and such.

Another thing because everything in powershell is an object. They all have
the common properties of system.object. Most useful of which is GetType()
method.

I hope this helps... let me know if you have any further questions.


"Art" <Art@discussions.microsoft.com> wrote in message
news:4865F9B3-3A83-4FA3-900D-8821ADDFE35E@microsoft.com...
> Brandon,
>
> Thanks, it works. Although it raises a new question. When I set $a=$pwd,
> and then type $a, I get a display that begins with "path" underscored and
> then the string holding the path. Then, when I try dir $a, I get what I
> want, but I'm confused as to why -- and also confused as to what's really
> in
> $a at this point.
>
> Can you tell me what's going on?
>
>
>
> "Brandon Shell" wrote:
>
>> If you want just assign your current path to a var....
>> $a = $pwd # $pwd is a special variable that contains current path
>> will work.
>>
>> "Art" <Art@discussions.microsoft.com> wrote in message
>> news:1259914D-06EB-47A9-ADB2-3FC083F6FE6E@microsoft.com...
>> > Suppose I travel down a directory tree until I wind up with:
>> > c:\documents and settings\Art\Math
>> > I'd like to assign a variable to this path so I don't have to stay
>> > there.
>> > I
>> > can type one in as "$a="c:\documents and settings\Art\Math". Is there
>> > a
>> > way
>> > to capture or copy it so that I can assign my variable without the
>> > typing?
>> >

>>
>>


My System SpecsSystem Spec
Old 03-13-2007   #8 (permalink)
Art
Guest


 

Re: Another question about directories

Marty,

Sorry it took me so long to get back to you. The info you provided is great
-- of course it makes wonder about a few other things, such as are typical
..net methods available in PowerShell. Also, when running "dir" and getting a
subset of the available members, is this something like the ToString method.
No need to answer -- I really appreciate the help you've provided.

"Marty List" wrote:

>
> Any time you want to know what type of object is stored in a variable, use
> |get-member or the variable's .GetType() method:
>
> PS>$a=gl
> PS>$a|gm
> TypeName: System.Management.Automation.PathInfo
> <snip>
> PS>$a.GetType()
>
> IsPublic IsSerial Name BaseType
> -------- -------- ---- --------
> True False PathInfo System.Object
>
> PS>$a.ToString()
> D:\Tmp
> PS>$a.Path
> D:\Tmp
> PS>$a.Path.GetType()
>
> IsPublic IsSerial Name BaseType
> -------- -------- ---- --------
> True True String System.Object
>
>
> I don't know if the stack can be manipulated, at first glance I don't see
> anything about it:
> get-help push-location -full
>
>
> "Art" <Art@discussions.microsoft.com> wrote in message
> news:157F44F1-AE75-4AC4-8550-C58BD0818398@microsoft.com...
> > Thanks Marty, it worked. Your answer raised a few questions. First is
> > the
> > question about what's actually in $a -- I asked about that in my response
> > to
> > Brandon. Your answer raised yet another question -- the stack. Is there
> > a
> > way to manipulate this stack? For example, can I pop the stack into a
> > variable or push things other than the location onto the stack, or can I
> > swap
> > the top elements or access something below the top of the stack?
> >
> > I didn't know there was a stack, so this is very interesting.
> >
> > "Marty List" wrote:
> >
> >>
> >> Hi Art,
> >>
> >> Try:
> >> $a=Get-Location
> >> or use an alias:
> >> $a=gl
> >> $a=pwd
> >>
> >> Also, see the Push-Location Pop-Location cmdlets:
> >>
> >> Push-Location -?
> >> Pop-Location -?
> >>
> >> Or use an alias (pushd / popd)
> >>
> >>
> >> "Art" <Art@discussions.microsoft.com> wrote in message
> >> news:1259914D-06EB-47A9-ADB2-3FC083F6FE6E@microsoft.com...
> >> > Suppose I travel down a directory tree until I wind up with:
> >> > c:\documents and settings\Art\Math
> >> > I'd like to assign a variable to this path so I don't have to stay
> >> > there.
> >> > I
> >> > can type one in as "$a="c:\documents and settings\Art\Math". Is there
> >> > a
> >> > way
> >> > to capture or copy it so that I can assign my variable without the
> >> > typing?
> >> >
> >>

>

My System SpecsSystem Spec
Old 03-15-2007   #9 (permalink)
Marty List
Guest


 

Re: Another question about directories


I'm not sure what you're asking when you say "it makes wonder about a few
other things, such as are typical .net methods available in PowerShell".

Also, when you say "is this something like the ToString method" think the
answer is no, because "dir" is an alias for get-childitem (get-alias dir)
and get-childitem does not return a string, it returns a
System.IO.DirectoryInfo object:

PS>$a=get-childitem c:\ -filter w*
PS>$a.GetType()

IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True DirectoryInfo
System.IO.FileSystemInfo


PS>$a|gm
TypeName: System.IO.DirectoryInfo
<snip>



"Art" <Art@discussions.microsoft.com> wrote in message
news:F3EC89ED-69EC-405C-A06E-FE7FFF6C6D32@microsoft.com...
> Marty,
>
> Sorry it took me so long to get back to you. The info you provided is
> great
> -- of course it makes wonder about a few other things, such as are typical
> .net methods available in PowerShell. Also, when running "dir" and
> getting a
> subset of the available members, is this something like the ToString
> method.
> No need to answer -- I really appreciate the help you've provided.
>
> "Marty List" wrote:
>
>>
>> Any time you want to know what type of object is stored in a variable,
>> use
>> |get-member or the variable's .GetType() method:
>>
>> PS>$a=gl
>> PS>$a|gm
>> TypeName: System.Management.Automation.PathInfo
>> <snip>
>> PS>$a.GetType()
>>
>> IsPublic IsSerial Name BaseType
>> -------- -------- ---- --------
>> True False PathInfo System.Object
>>
>> PS>$a.ToString()
>> D:\Tmp
>> PS>$a.Path
>> D:\Tmp
>> PS>$a.Path.GetType()
>>
>> IsPublic IsSerial Name BaseType
>> -------- -------- ---- --------
>> True True String System.Object
>>
>>
>> I don't know if the stack can be manipulated, at first glance I don't see
>> anything about it:
>> get-help push-location -full
>>
>>
>> "Art" <Art@discussions.microsoft.com> wrote in message
>> news:157F44F1-AE75-4AC4-8550-C58BD0818398@microsoft.com...
>> > Thanks Marty, it worked. Your answer raised a few questions. First is
>> > the
>> > question about what's actually in $a -- I asked about that in my
>> > response
>> > to
>> > Brandon. Your answer raised yet another question -- the stack. Is
>> > there
>> > a
>> > way to manipulate this stack? For example, can I pop the stack into a
>> > variable or push things other than the location onto the stack, or can
>> > I
>> > swap
>> > the top elements or access something below the top of the stack?
>> >
>> > I didn't know there was a stack, so this is very interesting.
>> >
>> > "Marty List" wrote:
>> >
>> >>
>> >> Hi Art,
>> >>
>> >> Try:
>> >> $a=Get-Location
>> >> or use an alias:
>> >> $a=gl
>> >> $a=pwd
>> >>
>> >> Also, see the Push-Location Pop-Location cmdlets:
>> >>
>> >> Push-Location -?
>> >> Pop-Location -?
>> >>
>> >> Or use an alias (pushd / popd)
>> >>
>> >>
>> >> "Art" <Art@discussions.microsoft.com> wrote in message
>> >> news:1259914D-06EB-47A9-ADB2-3FC083F6FE6E@microsoft.com...
>> >> > Suppose I travel down a directory tree until I wind up with:
>> >> > c:\documents and settings\Art\Math
>> >> > I'd like to assign a variable to this path so I don't have to stay
>> >> > there.
>> >> > I
>> >> > can type one in as "$a="c:\documents and settings\Art\Math". Is
>> >> > there
>> >> > a
>> >> > way
>> >> > to capture or copy it so that I can assign my variable without the
>> >> > typing?
>> >> >
>> >>

>>


My System SpecsSystem Spec
Old 03-15-2007   #10 (permalink)
Marty List
Guest


 

Re: Another question about directories


Just to clarify, get-childitem doesn't always return DirectoryInfo objects,
like it does in this discussion (about directories, get-location, etc.).

Get-ChildItem will return different object types for files or other
providers other than the file system (see Get-PSProvider)


"Marty List" <usenet@optimumx.com> wrote in message
news:OB88Sz2ZHHA.3268@TK2MSFTNGP04.phx.gbl...
>
> I'm not sure what you're asking when you say "it makes wonder about a few
> other things, such as are typical .net methods available in PowerShell".
>
> Also, when you say "is this something like the ToString method" think the
> answer is no, because "dir" is an alias for get-childitem (get-alias dir)
> and get-childitem does not return a string, it returns a
> System.IO.DirectoryInfo object:
>
> PS>$a=get-childitem c:\ -filter w*
> PS>$a.GetType()
>
> IsPublic IsSerial Name BaseType
> -------- -------- ---- --------
> True True DirectoryInfo System.IO.FileSystemInfo
>
>
> PS>$a|gm
> TypeName: System.IO.DirectoryInfo
> <snip>
>
>
>
> "Art" <Art@discussions.microsoft.com> wrote in message
> news:F3EC89ED-69EC-405C-A06E-FE7FFF6C6D32@microsoft.com...
>> Marty,
>>
>> Sorry it took me so long to get back to you. The info you provided is
>> great
>> -- of course it makes wonder about a few other things, such as are
>> typical
>> .net methods available in PowerShell. Also, when running "dir" and
>> getting a
>> subset of the available members, is this something like the ToString
>> method.
>> No need to answer -- I really appreciate the help you've provided.
>>
>> "Marty List" wrote:
>>
>>>
>>> Any time you want to know what type of object is stored in a variable,
>>> use
>>> |get-member or the variable's .GetType() method:
>>>
>>> PS>$a=gl
>>> PS>$a|gm
>>> TypeName: System.Management.Automation.PathInfo
>>> <snip>
>>> PS>$a.GetType()
>>>
>>> IsPublic IsSerial Name BaseType
>>> -------- -------- ---- --------
>>> True False PathInfo System.Object
>>>
>>> PS>$a.ToString()
>>> D:\Tmp
>>> PS>$a.Path
>>> D:\Tmp
>>> PS>$a.Path.GetType()
>>>
>>> IsPublic IsSerial Name BaseType
>>> -------- -------- ---- --------
>>> True True String System.Object
>>>
>>>
>>> I don't know if the stack can be manipulated, at first glance I don't
>>> see
>>> anything about it:
>>> get-help push-location -full
>>>
>>>
>>> "Art" <Art@discussions.microsoft.com> wrote in message
>>> news:157F44F1-AE75-4AC4-8550-C58BD0818398@microsoft.com...
>>> > Thanks Marty, it worked. Your answer raised a few questions. First
>>> > is
>>> > the
>>> > question about what's actually in $a -- I asked about that in my
>>> > response
>>> > to
>>> > Brandon. Your answer raised yet another question -- the stack. Is
>>> > there
>>> > a
>>> > way to manipulate this stack? For example, can I pop the stack into a
>>> > variable or push things other than the location onto the stack, or can
>>> > I
>>> > swap
>>> > the top elements or access something below the top of the stack?
>>> >
>>> > I didn't know there was a stack, so this is very interesting.
>>> >
>>> > "Marty List" wrote:
>>> >
>>> >>
>>> >> Hi Art,
>>> >>
>>> >> Try:
>>> >> $a=Get-Location
>>> >> or use an alias:
>>> >> $a=gl
>>> >> $a=pwd
>>> >>
>>> >> Also, see the Push-Location Pop-Location cmdlets:
>>> >>
>>> >> Push-Location -?
>>> >> Pop-Location -?
>>> >>
>>> >> Or use an alias (pushd / popd)
>>> >>
>>> >>
>>> >> "Art" <Art@discussions.microsoft.com> wrote in message
>>> >> news:1259914D-06EB-47A9-ADB2-3FC083F6FE6E@microsoft.com...
>>> >> > Suppose I travel down a directory tree until I wind up with:
>>> >> > c:\documents and settings\Art\Math
>>> >> > I'd like to assign a variable to this path so I don't have to stay
>>> >> > there.
>>> >> > I
>>> >> > can type one in as "$a="c:\documents and settings\Art\Math". Is
>>> >> > there
>>> >> > a
>>> >> > way
>>> >> > to capture or copy it so that I can assign my variable without the
>>> >> > typing?
>>> >> >
>>> >>
>>>

>


My System SpecsSystem Spec
Closed Thread
Update your Vista Drivers Update Your Drivers Now!!

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
List FTP Directories Bushman PowerShell 3 03-04-2008 07:40 AM
FTP whole directories? Mike C Vista General 4 01-11-2008 09:37 AM
merge directories marty Vista General 0 10-05-2007 01:09 PM
Problems with Directories Idiot_Ronin Vista General 0 08-16-2007 07:53 PM
Linking Directories =?Utf-8?B?R3JlZw==?= PowerShell 2 09-05-2006 03:42 PM


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 51