Jump to content
Sign in to follow this  
AcidCorps

FileGetPiece UDF

Recommended Posts

AcidCorps

Func FileGetPiece($shFile, $xvFlag = 0)
    ;0 = All
    ;1 = Filename
    ;2 = Extension
    ;4 = Filename - Extension
    If $xvFlag = 0 Then Dim $vsOut[3]; 1, 2, 4
    If $xvFlag = 1 Then Dim $vsOut[1]; 1
    If $xvFlag = 2 Then Dim $vsOut[1]; 2
    If $xvFlag = 3 Then Dim $vsOut[2]; 1, 2
    If $xvFlag = 4 Then Dim $vsOut[1]; 4
    If $xvFlag = 5 Then Dim $vsOut[2]; 1,4
    If $xvFlag = 6 Then Dim $vsOut[2]; 2, 4
    
    If $xvFlag = 1 Or $xvFlag = 2 Or $xvFlag = 4 Then Dim $vsOut[1]
    If $xvFlag = 3 Or $xvFlag = 5 Or $xvFlag = 6 Then Dim $vsOut[2]
    
    If $xvFlag = 0 Or $xvFlag = 1 Or $xvFlag = 3 Or $xvFlag = 5 Then $vsFilename = StringTrimLeft($shFile, StringInStr($shFile, '\', 0, -1))
    If $xvFlag = 0 Or $xvFlag = 2 Or $xvFlag = 3 Or $xvFlag = 6 Then $vsExtension = '.' & StringTrimLeft($shFile, StringInStr($shFile, '.', 0 -1))
    If $xvFlag = 0 Or $xvFlag = 4 Or $xvFlag = 5 Or $xvFlag = 6 Then $vsFile = StringTrimRight(StringReplace(StringTrimLeft($shFile, StringInStr($shFile, '\', 0, -1)), StringTrimLeft($shFile, StringInStr($shFile, '.', 0, -1)), ''), 1)
    
    If $xvFlag = 1 Then Return $vsFilename
    If $xvFlag = 2 Then Return $vsExtension
    If $xvFlag = 4 Then Return $vsFile
    If $xvFlag = 3 Then
        Dim $vsOut[2]
        $vsOut[0] = $vsFilename
        $vsOut[1] = $vsExtension
        Return $vsOut
    EndIf
    If $xvFlag = 5 Then
        Dim $vsOut[2]
        $vsOut[0] = $vsFilename
        $vsOut[1] = $vsFile
        Return $vsOut
    EndIf
    If $xvFlag = 6 Then
        Dim $vsOut[2]
        $vsOut[0] = $vsExtension
        $vsOut[1] = $vsFile
        Return $vsOut
    EndIf
    If $xvFlag = 7 Or $xvFlag = 0 Then
        Dim $vsOut[3]
        $vsOut[0] = $vsFilename
        $vsOut[1] = $vsExtension
        $vsOut[2] = $vsFile
        Return $vsOut
    EndIf
EndFunc

Examples:

$File = 'C:\My File.au3'

FileGetPiece($File, 1) Returns My File.au3

FileGetPiece($File, 2) Returns .au3

FileGetPiece($File, 4) Returns My File

Combining the flags will result in an array containing the combined returns

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.