BlitzCoder Essentials
•
Home Page
•
About BlitzCoder
•
Contributors
•
Terms of Use
•
Email Us
Main Areas
•
BlitzCoder Chat
•
Discussions
•
Articles/Tutorials
•
Code Database
•
Link Database
•
Showcase Area
•
Worklogs
•
Competitions
Special Areas
•
Undocumented
Other Blitz Sites
•
Blitz Basic Home
•
Blitz Showcase
•
BlitzPlay Library
Forum Login
Username:
Password:
•
Register Now!
BlitzCoder Code Archives Page
Main Codes Page
"Extract filename functions"
, by kefir
ExtractFileName$() , ExtractFileExt$() , ExtractFileNameWithoutExt$() , ExtractFilePath$() , ExtractRelativeFileName$() , UnExtractRelativeFileName$()
Code
Function ExtractFileName$(FileName$) If FileName$="" Or Instr(FileName$,"\")=0 Return "" index=1 While index>0 oldindex=index index=Instr(FileName$,"\",oldindex+1) Wend Return Replace$(Mid$(FileName$,oldindex+1),"\\","\") End Function Function ExtractFileExt$(FileName$) If FileName$="" Or Instr(FileName$,".")=0 Return "" index=1 While index>0 oldindex=index index=Instr(FileName$,".",oldindex+1) Wend Return Replace$(Mid$(FileName$,oldindex+1),"\\","\") End Function Function ExtractFileNameWithoutExt$(FileName$, WithPath=True) If FileName$="" Return "" If WithPath=False And Instr(FileName$,"\")<>0 Then index=1 While index>0 oldindex=index index=Instr(FileName$,"\",oldindex+1) Wend FileName$ = Mid$(FileName$,oldindex+1) EndIf If Instr(FileName$,".")<>0 Then index=1 While index>0 oldindex=index index=Instr(FileName$,".",oldindex+1) Wend Return Mid$(FileName$,1,oldindex-1) Else Return FileName$ EndIf End Function Function ExtractFilePath$(FileName$) If FileName$="" Or Instr(FileName$,"\")=0 Return CurrentDir$() index=1 While index>0 oldindex=index index=Instr(FileName$,"\",oldindex+1) Wend Return Replace$(Left$(FileName$,oldindex),"\\","\") End Function Function ExtractRelativeFileName$(FileName$, Path$) Path$ = Upper$(path$) FileName$ = Upper(FileName$) If Left$(FileName$,Len(Path$)) = Path$ Then Return Replace$(Right$(FileName$,Len(FileName$)-Len(Path$)),"\\","\") Else ;If FileType(Path$+FileName$) Return Replace$(FileName$,"\\","\") EndIf End Function Function UnExtractRelativeFileName$(FileName$, Path$) Path$ = Upper$(Path$) FileName$ = Upper(FileName$) If FileType(Path$+FileName$) Then Return Replace$(Path$+FileName$,"\\","\") Else Return Replace$(FileName$,"\\","\") EndIf End Function
Copyright(c) 2000-2004, BlitzCoder. All Rights Reserved.
Code software created by Krylar's Kreations