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

Basename without extension

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 04-09-2007   #1 (permalink)
Keith Hill [MVP]
Guest


 

Basename without extension

This is one area where I think Korn shell is easier - determining the basename of a script san path and extension.

SCRIPTNAME=$(basename $0 .ksh)

versus the PowerShell way:

$ScriptName = [system.io.path]::GetFilenameWithoutExtension($MyInvocation.InvocationName)

What I would like to see is something like this:

$ScriptName = Split-Path $MyInvocation.InvocationName -leaf -noExt

It's not dramaticall fewer characters to type however you don't have to drop down to the .NET framework to strip an extension off a filename.

--
Keith

My System SpecsSystem Spec
Old 04-09-2007   #2 (permalink)
mikes.net
Guest


 

Re: Basename without extension

Well, there's always this:

(split-path $path.ps1 -leaf).split(".")[0]

Not terribly unreasonable, but I agree that a noExtension would be
nice, and actually, expected.

Mike


On Apr 9, 11:55 am, "Keith Hill [MVP]"
<r_keith_h...@no.spam.thank.u.hotmail.com> wrote:
> This is one area where I think Korn shell is easier - determining the basename of a script san path and extension.
>
> SCRIPTNAME=$(basename $0 .ksh)
>
> versus the PowerShell way:
>
> $ScriptName = [system.io.path]::GetFilenameWithoutExtension($MyInvocation.InvocationName)
>
> What I would like to see is something like this:
>
> $ScriptName = Split-Path $MyInvocation.InvocationName -leaf -noExt
>
> It's not dramaticall fewer characters to type however you don't have to drop down to the .NET framework to strip an extension off a filename.
>
> --
> Keith



My System SpecsSystem Spec
Old 04-09-2007   #3 (permalink)
Jacques Barathon [MS]
Guest


 

Re: Basename without extension

"mikes.net" <michael.net@gmail.com> wrote in message
news:1176138028.791197.20160@w1g2000hsg.googlegroups.com...
> Well, there's always this:
>
> (split-path $path.ps1 -leaf).split(".")[0]
>
> Not terribly unreasonable, but I agree that a noExtension would be
> nice, and actually, expected.


Personally I have extended the File type so that I can do this:

PS> $file = "myscript.ps1"
PS> (gci $file).basename
myscript

Basename is a very simple ScriptProperty that says this:

[IO.Path]::GetFileNameWithoutExtension($this)

Maybe this property should be included as a default. Feel free to submit the
suggestion if it makes sense to you.

Jacques

My System SpecsSystem Spec
Old 04-09-2007   #4 (permalink)
Keith Hill
Guest


 

Re: Basename without extension

"mikes.net" <michael.net@gmail.com> wrote in message
news:1176138028.791197.20160@w1g2000hsg.googlegroups.com...
> Well, there's always this:
>
> (split-path $path.ps1 -leaf).split(".")[0]
>
> Not terribly unreasonable, but I agree that a noExtension would be
> nice, and actually, expected.


I submitted this. Vote on it if you like:

https://connect.microsoft.com/feedba...9716&SiteID=99

--
Keith

My System SpecsSystem Spec
Old 04-10-2007   #5 (permalink)
Sung M Kim
Guest


 

Re: Basename without extension

seems like a great time saver "IMO"

My System SpecsSystem Spec
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot Open msg extension bnbriely Vista mail 1 11-16-2007 08:06 PM
wmv Extension Roosevelt Vista mail 2 10-23-2007 10:17 AM
File Extension Lothar PowerShell 5 12-12-2006 05:35 PM
Suggestion: Add a Basename property to System.IO.FileInfo Alex K. Angelopoulos [MVP] PowerShell 5 06-25-2006 09:39 AM
New extension Danny [mess.es] Vista mail 14 05-27-2006 08:52 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 51