![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
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.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| 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 Specs![]() |
| | #2 (permalink) |
| 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 Specs![]() |
| | #3 (permalink) |
| 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 Specs![]() |
| | #4 (permalink) |
| 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 Specs![]() |
| | #5 (permalink) |
| Guest | Re: Basename without extension seems like a great time saver "IMO" |
My System Specs![]() |
![]() |
| 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 |