Question about converting a string

Blitz3D Forums/Blitz3D Beginners Area/Question about converting a string

Jeroen(Posted 2003) [#1]
Hi!

Simple question, but I don't know how to do it.
I'd like to convert a filename with full path to only the filename.

E.g:
c:\myFolder\myFiles\blah.txt
to:
blah.txt

How can I do this?
THANKS


Neo Genesis10(Posted 2003) [#2]
Function ClipFilepath$( filepath$ )
	For I = Len(filepath$) To 1 Step -1
		tmp$ = Mid$(filepath$,I,1)
		If (tmp$ = "/") Or (tmp$ = "\") Return Mid$(filepath$, I+1)
	Next
	Return filepath$
End Function



SJT(Posted 2003) [#3]
Off the top of my head, not tested,

file$="c:\folder\myfiles\blah.txt"
name$=""
x=Len(file$)

Repeat
   if mid$(file$,x,1)="\" then
      name$=mid$(file$,x+1)
   end if
   x=x-1
until name$<>"" or x=0



check my syntax.

SJT


SJT(Posted 2003) [#4]
Can you just jump out of a for next loop?

SJT


FlameDuck(Posted 2003) [#5]
Can you just jump out of a for next loop?
Yeah, it's called 'Exit'.
Or you could just use a while loop instead.


Jeroen(Posted 2003) [#6]
Hey thanks guys! Works great!