Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista Tutorial - elegant way to get path and file name

Reply
 
Old 08-25-2008   #1 (permalink)
George
Guest


 
 

elegant way to get path and file name

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

My System SpecsSystem Spec
Old 08-25-2008   #2 (permalink)
Jeff
Guest


 
 

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
Old 08-25-2008   #3 (permalink)
Kiron
Guest


 
 

RE: elegant way to get path and file name

# PowerShell's Split-Path can do this for you:
# parent path:
split-path c:\myproject\Csharpproject\memo.txt -Parent
# same as above, w/o the -Parent switch:
split-path c:\myproject\Csharpproject\memo.txt
# file name:
split-path c:\myproject\Csharpproject\memo.txt -Leaf

# ...and more:
split-path c:\myproject\Csharpproject\memo.txt -Qualifier
split-path c:\myproject\Csharpproject\memo.txt -NoQualifier
split-path c:\myproject\Csharpproject\memo.txt -IsAbsolute

--
Kiron
My System SpecsSystem Spec
Old 08-25-2008   #4 (permalink)
George
Guest


 
 

Re: elegant way to get path and file name

Thanks Jeff,


Cool!


regards,
George
My System SpecsSystem Spec
Old 08-25-2008   #5 (permalink)
George
Guest


 
 

RE: elegant way to get path and file name

Cool, Kiron!


regards,
George
My System SpecsSystem Spec
Old 09-04-2008   #6 (permalink)
Newbie


Join Date: Sep 2008
No idea
 
 

Re: elegant way to get path and file name

I cannot even find out how to insert the path and filename anymore with Vista. Help.
My System SpecsSystem Spec
Old 09-05-2008   #7 (permalink)
George
Guest


 
 

Re: elegant way to get path and file name

What do you mean "insert the path and filename anymore", rsgreer?


regards,
George
My System SpecsSystem Spec
Old 09-05-2008   #8 (permalink)
Newbie


Join Date: Sep 2008
No idea
 
 

Re: elegant way to get path and file name

I want to place a path and filename on all of my documents like I did in the older version, however, I cannot seem to find out how to do this?? It is simple I am sure, I just don't see it.
My System SpecsSystem Spec
Old 09-08-2008   #9 (permalink)
George
Guest


 
 

Re: elegant way to get path and file name

Thanks rsgreer,


I think it is very clear in this discussion how to retrieve path and
relative name parts of a absolute path file name. What is your specific
confusion? :-)


regards,
George
My System SpecsSystem Spec
Old 09-08-2008   #10 (permalink)
Newbie


Join Date: Sep 2008
No idea
 
 

Re: elegant way to get path and file name

You keep saying that but I haven't once seen someone write go to file, scroll down, add path and file name. If you are not able to write the directions we can stop this
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
finding path to an .exe file Vista file management
Retrieve the path of the file PowerShell
File Path Problem Vista General
I miss the elegant simplicity........ Live Mail
BUG? (Test-Path $path -IsValid) and empty $path PowerShell


Vista Forums 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 Ltd

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