Title : Get Filename/Folder/Extension
Author : Nebula
Posted : 1+ years ago
Description : I was modifying some code and I needed only the filename from a string that contained the entire path. So I coded a function for this and two others just for the heck of it.
filename$ = getfilename$(path_and_file)$
extension$ = getextension$(path_and_file)$
directory$ = getdirectory$(path_and_file)$
filename$ would look like "renamed.bmp"
extension$ would look like "bmp"
directory$ would look like "c:gamespacmanIV" Code : Function getfilename$(filename$) ; Returns the filename and extension
lastdir = 1
For i=1 To Len(filename$)
If Mid$(filename$,i,1) = "" Then Lastdir = i
Next
If Lastdir > 1 Then Lastdir = Lastdir + 1
For i=Lastdir To Len(filename$)
a$ = a$ + Mid(filename$,i,1)
Next
Return a$
End Function
Function getextension$(filename$) ; Returns the extension minus the .
lastdir = 1
For i=1 To Len(filename$)
If Mid$(filename$,i,1) = "." Then Lastdir = i
Next
If Lastdir > 1 Then Lastdir = Lastdir + 1
For i=Lastdir To Len(filename$)
a$ = a$ + Mid(filename$,i,1)
Next
Return a$
End Function
Function getdirectory$(filename$) ; Returns the complete directory including drive
lastdir = 1
For i=1 To Len(filename$)
If Mid$(filename$,i,1) = "" Then Lastdir = i
Next
For i=1 To Lastdir
a$ = a$ + Mid(filename$,i,1)
Next
Return a$
End Function
Comments : none...