1.    09 Apr 2007 #1
    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

  2.    09 Apr 2007 #2
    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

  3.    09 Apr 2007 #3
    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

  4.    09 Apr 2007 #4
    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

  5.    10 Apr 2007 #5
    Sung M Kim Guest

    Re: Basename without extension


    seems like a great time saver "IMO"

      My System SpecsSystem Spec


Similar Threads
Thread Forum
.sig extension
I can't open a file with the extension .sig. Can anybody help
Browsers & Mail
file extension
Does anyone know how to change this: C:\Users\Darryl\Music\Pictures\Pictures\Pictures\Pictures\Pictures\Pictures\Pictures\2009-05-18 Huaraz...
Vista General
file extension?
Hello, I have a backup program that is not finding Windows Mail files. What is the file extension for Windows Mail and where does it reside please....
Vista mail
pps extension
I have newly installed Home and Student 2007 that includes PowerPoint and also have PowerPoint Viewer on a 64 bit Vista system, but still can't...
Vista General
wmv Extension
When I receive e-mail with wmv extensions, I cannot open them. I get an error message that reads: This file does not have a program associated...
Vista mail
Suggestion: Add a Basename property to System.IO.FileInfo
https://connect.microsoft.com/feedback/ViewFeedback.aspx?FeedbackID=145875&SiteID=99 Although file extension changing is a common technique in...
PowerShell
New extension
Hotmail change to Windows Live Mail any know what's the new domains in mail's ? @mail.com @live.com?
Vista mail

Our Sites
  • Ten Forums
  • Eight Forums
  • Seven Forums
  • PC Help Forum
  • Help Me Bake
  • Site Links
  • Contact Us
  • Privacy and Cookies
  • About Us
    Windows Vista Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

    Designer Media Ltd
    All times are GMT -5. The time now is 06:34.
    .