Archive: GetFileName question


GetFileName question
so far i was using the GetFileName function to detect the part before a ":" in my $var. i used this function to check protocols of a url (among other things!).

as it might appear that a port and/or a login-name is specified in an url, this function would not work here. i'm looking for a way to put everything left of the first ":" in $var1 to $var2.

any help?


Can you write an example


what i'm checking with GetFileName is

"http://www.google.com" (detects "http")
"md5:s0m3cH3ckSum" (detects "md5")
"ftp://ftp.bla.com" (detects "ftp")


this works well with the GetFileName function. however, as this function works from right/end to the left/beginning, it does not work for these examples:

"http://cerebrum.dnalounge.com:8001/audio/2005/04-29-45945.m3u" (detects "http://cerebrum.dnalounge.com" instead of "http")
"http://anonymous:none@www.google.com" (detects "http://anonymous" instead of "http")


that's why i'm looking for a way to check all text from the left of the first colon.


Name "Output"
OutFile "Output.exe"

!include "WordFunc.nsh"
!insertmacro WordFind

Section
${WordFind} 'http://cerebrum.dnalounge.com:8001/audio/2005/04-29-45945.m3u' ':' '+1{' $0

MessageBox MB_OK '$0'
SectionEnd


Or special variant :)
Name "Output"
OutFile "Output.exe"

Function ForYathosho
Exch $0
Push $1
Push $2

StrCpy $1 0
IntOp $1 $1 + 1
StrCpy $2 $0 1 $1
StrCmp $2 '' empty
StrCmp $2 ':' 0 -3
StrCpy $0 $0 $1
goto end

empty:
StrCpy $0 ''

end:
Pop $2
Pop $1
Exch $0
FunctionEnd

Section
Push 'http://cerebrum.dnalounge.com:8001/audio/2005/04-29-45945.m3u'
Call ForYathosho
Pop $0

MessageBox MB_OK '$0'
SectionEnd

thanks a lot!


i tried the second method, but the same problem appears when i tried "http://cerebrum.dnalounge.com:8001/audio/2005/04-29-45945.m3u"

will try wordfind now, looks very useful, but the function is also quite huge. ;)


That problem appears? ("http://cerebrum.dnalounge.com:8001/audio/2005/04-29-45945.m3u" -> "http")


Originally posted by Instructor
That problem appears? ("http://cerebrum.dnalounge.com:8001/audio/2005/04-29-45945.m3u" -> "http")
no, the output is "http://cerebrum.dnalounge.com", it should be "http" though

using wordfind now and it's even better for my purposes, as i can use one function to do multiple operations.. but i have another question!

my old code was

Push $URL
Call GetFileName
Pop $File

i replaced it with
${WordFind} "$URL" "/" "#" $R0
${WordFind} "$URL" "/" "+$R0}" $File

in each case $URL is a link to a file, the function is supposed to get the filname ($File). when i tested this script, i accidently had an url with two slashes at the wrong place ("http://myurl.com/dir//dir/myfile.txt").

my code didn't work then ($File = dir/myfile.txt), so i'm not sure if i made a mistake.

${WordFind} "$URL" "/" "-1}" $File


P.S.
Function ForYathosho output is "http" (Input: "http://cerebrum.dnalounge.com:8001/audio/2005/04-29-45945.m3u") :)