Code archives/Algorithms/LtoRLook()

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

Download source code

LtoRLook() by Zenn Lee2006
If you are trying to add more than 1 file into a directory, while using RequestFile(), use this function to move up to the last "\" from right.

You enter the string you want to search and then you enter the char. you want to end at.
Lets say you have this string "C:\Documents and Settings\Administrator\file.txt" and you want to add another file into the dir. above. You can use LtoRLook() to cut "C:\Documents and Settings\Administrator\file.txt" to "C:\Documents and Settings\Administrator\"

Example: Lets say you want to save a .wav with the name returned by RequestFile() but you also wanted to save a .exe in that same directory.

Global File$ = ""
File$ = RequestFile("Save File","Wave Files:wav;",True)
CopyFile("Sound.wav",File$)
CopyFile("file2.exe",LtoRLook(File$,"\") + File2 +".exe")

I know this function is simple but it has come in handy many times.
Function LtoRLook:String(Str$,Char$)
 L = Len(Str$)
 While Not L = 0 
  L = L - 1
  ReturnStr$ = Left(Str$,L)
  If Mid(ReturnStr$,L,1) = Char$
   Return ReturnStr$
   L = 0
  End If
 Wend
End Function

Comments

Brucey2007
Although for files, it might be easier to use :

dir$ = ExtractDir(file$)


:o)


Zenn Lee2007
oh?!


Code Archives Forum