View Single Post
Old 08-25-2008   #2 (permalink)
Jeff


 
 

Re: elegant way to get path and file name

On Aug 26, 7:59*am, George <Geo...@xxxxxx> wrote:
Quote:

> Hello everyone,
>
> Suppose I have a string representing a file name (absolute name), like
> "c:\myproject\Csharpproject\memo.txt", I want to retrieve the path like
> c:\myproject\Cshartproject and relative file name memo.txt separately.
>
> thanks in advance,
> George
George,

The Get-ChildItem Cmdlet returns a FileInfo object, which you can use
to get these properties:

PSH$ $file = Get-ChildItem "c:\myproject\Csharpproject\memo.txt"

PSH$ $file.DirectoryName
c:\myproject\Csharpproject

PSH$ $file.Name
memo.txt


Jeff
My System SpecsSystem Spec