Yathosho
11th May 2005 11:02 UTC
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?
Instructor
11th May 2005 11:10 UTC
Can you write an example
Yathosho
11th May 2005 11:29 UTC
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.
Instructor
11th May 2005 12:29 UTC
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
Yathosho
11th May 2005 12:46 UTC
thanks a lot!
Yathosho
11th May 2005 18:52 UTC
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. ;)
Instructor
11th May 2005 18:56 UTC
That problem appears? ("http://cerebrum.dnalounge.com:8001/audio/2005/04-29-45945.m3u" -> "http")
Yathosho
11th May 2005 19:06 UTC
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
Yathosho
11th May 2005 23:51 UTC
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.
Instructor
12th May 2005 09:10 UTC
${WordFind} "$URL" "/" "-1}" $File
P.S.
Function ForYathosho output is "http" (Input: "http://cerebrum.dnalounge.com:8001/audio/2005/04-29-45945.m3u") :)