Code archives/Miscellaneous/Get File Function

This code has been declared by its author to be Public Domain code.

Download source code

Get File Function by xmlspy
(Posted 20 years ago)
This function will remove the path of a file in a string.
;xmlspy - 2006
;xmlspy_gt@hotmail.com
;www.alldevs.com
;Removes path

Print Get_File("c:\documents\myfile.txt")
Delay 1000

Function Get_File$(file$)
	For i = 1 To Len(file$)
		If Mid$(file$,i,1) = "\" Then
			c = 0
		EndIf
		c = c + 1
	Next
	Return Right(file$, c-1)
End Function

Comments

SebHoll
(Posted 20 years ago)
In your function you are going from left to right until you reach the last "\". Wouldn't it be more effecient to go from right to left and stop at the first "\"?

Function Get_File$(file$)

For i = Len(file$) To 1 Step -1

	If Mid$(file$,i,1) = "" Then Exit

Next

Return Right$(file$,Len(file$)-i)

End Function


BlitzSupport
(Posted 20 years ago)
Bear in mind you can use both "\" and "/" to describe paths in Blitz...

xmlspy
(Posted 20 years ago)
The function works for my purpose... but yes going from right to left is probably faster.

Code Archives Forum