This blog has moved to http://ThePowerShellGuy.com
In Monad there are some handy tools to work with a path,
I want to mention some I think are the most handy here.
Also I get to the differences between a path in MSH and in CMD, as in MSH it’s not always a disk we are referring to here, but more about that later.First test-path
Test-path does what the most of you are used to do with IF EXIST in batch files.
MSH>test-path c:\test\* -ex *.txt
MSH>test-path c:\test\*.* -ex *.txt
The last 2 are interesting, the question asked to test-path is here :
The first is Does c:\test contain any Items other then text files ?
(in my case there was a subdirectory of test)
Then I nice one I found in Resolve Path
what does this do ?
resolves the users Home directory ;-)(I don’t know where the ~ comes from, It does not work on his own, nor have I seen it anywhere else yet.)
C:\Documents and Settings\mow
And another nice one :
get the current location on the drive(provider) where the homedirectory is.Very useful ;-)
But more serious .. the point here is that you get access to the Drive Object …
And you can also use wildcards here to get more objects back.
A bit more usefull ?Combine-path
MSH>combine-path c:\test\ \monad
MSH>combine-path c:\test\ /monad
as you can see in this example this is more safe than just to use a string for this, as this class has some logic (it sees that both parts contain the delimiter and removes one)
Also, remember a drive in Monad is actually a Provider, so to be save use the combine-path command for this, then you use the MshPath as the glue, (This is also the wrapper that provides the use of / in MSH), before use the path gets resolved to a format the Provider is familiar with.
See also the difference here :
MSH>cd hklm: ; (gi .).MshPath
will give you the path as it is presented to the provider.
I only tipped at some of the uses of the Path commandlets and the difference between a path in MSH and in CMD, i would reccomend you look at there help a bit, and in the beta documentation (see $links), and I would like to give you some other examples of working with a path in MSH.
maybe some thinks will look a bit strange at first, but if you play a bit with them they are prety powerfull tools,
Some Tips are don't think to much filesystem think Provider and don't use test parsing if you don't realy need it (think Oject ;-).
As always with Monad using get-member a lot will help also .