Code archives/Miscellaneous/Get File Function
This code has been declared by its author to be Public Domain code.
Download source code
| |||||
This function will remove the path of a file in a string. | |||||
;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
| ||
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 |
| ||
Bear in mind you can use both "\" and "/" to describe paths in Blitz... |
| ||
. |
Code Archives Forum