Home Dashboard Directory Help

Add a Basename property to System.IO.FileInfo by Alex Angelopoulos


Status: 

Resolved
 as Postponed Help for as Postponed


7
0
Sign in
to vote
Type: Suggestion
ID: 145875
Opened: 6/24/2006 11:06:46 AM
Access Restriction: Public
0
Workaround(s)
view

Description

Although file extension changing is a common technique in administrative tasks, the System.IO.FileInfo class does not provide a direct Basename property and neither does PowerShell.

This is useful enough that I believe it should be added to PS typedata. It can actually be done with a simple ScriptProperty, as shown below:

        <Type>
            <Name>System.IO.FileInfo</Name>
            <Members>
                <ScriptProperty>
                    <Name>Basename</Name>
                    <GetScriptBlock>
                        $this.Name.Remove($this.Name.Length - $this.Extension.Length);
                    </GetScriptBlock>
                </ScriptProperty>
            </Members>
        </Type>    
Details
Sign in to post a comment.
Sign in to post a workaround.