Login Register
Frontpage Code library Pastebin

GetFileName

Author: VesQ
Added: 11.4.2011 3:45
Edited: 15.4.2011 22:19
Category: Merkkijonot

Description

Palauttaa tiedoston nimen absoluuttisesta tai relativiisesta polusta.

Code

Select all
 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
//================================================================================
// GetFileName-funktio [ VesQ ]
// ----------------------------
// Palauttaa tiedoston nimen absoluuttisesta tai relativiisesta polusta.
//================================================================================


// ESIMERKKI
searchAbsolutive$ = "C:\lolwhatadir/asdf/this\maps/Luna.mpc"
searchRelative$ = "media/long\list/of/directories\ukko.bmp"

Print GetFileName( searchAbsolutive$ )
Print GetFileName( searchRelative$ )
Print GetFileName( GetEXEName() )

WaitKey 

// FUNKTIO
Function GetFileName( _path$ )

    searchParam$ = Replace( _path$, "/", "\" )
    
    fileNameTmp = 1
    searchLen = Len( searchParam$ )
    While InStr( searchParam$, "\", fileNameTmp ) > 0
        fileNameTmp = fileNameTmp + 1
        If fileNameTmp > searchLen Then
            Exit
        EndIf
    Wend 
    
    ret$ = Mid( searchParam$, fileNameTmp )
    
    Return ret$
EndFunction

Comments

No comments. You can be first!

Leave a comment

You must be logged in to comment.