Page 1 of 1

problem with %PathName, %FileName in LUA

Posted: Mon Nov 30, 2020 2:18 am
by JohnsonCat
i just noticed our LUA script not always works.
the script is

if string.find(string.lower('%PathName'), '/gct/3. booking token applied/') then
do something
en

for example, when the file is D://WFTP/Data/GCT/3. Booking token applied/a) Customer sample with booking ticket/Gold Class Hopper BRT Token 27-11-2020.xlsx, i can see an error 'Failed to execute lua script of event'

i initially though that was because of '-', but other files with '-' seem to be fine when in other folders.
An ideas?

Re: problem with %PathName, %FileName in LUA

Posted: Mon Nov 30, 2020 3:48 am
by JohnsonCat
or maybe there's a length limit of %PathName can return?

Re: problem with %PathName, %FileName in LUA

Posted: Mon Nov 30, 2020 3:44 pm
by FTP
I just tested with your script in the event "OnFileUploaded", everything is OK. Is it because that you missed a character "d" in the end? It should be:

Code: Select all

if string.find(string.lower('%PathName'), '/gct/3. booking token applied/') then
...
end

Re: problem with %PathName, %FileName in LUA

Posted: Mon Nov 30, 2020 11:16 pm
by JohnsonCat
that was just not pasted from the code.

Re: problem with %PathName, %FileName in LUA

Posted: Tue Dec 01, 2020 5:21 am
by FTP
OK, so I think the error was caused by the code after "then", please check it.

Re: problem with %PathName, %FileName in LUA

Posted: Wed Dec 02, 2020 2:01 am
by JohnsonCat
after massive tests i think it's string.find and string.match don't like ')' in the strings.
for example:
if string.find(string.lower('%PathName'), '/gct/3. booking token applied/') then
do something
end

this is fine, but
if string.find(string.lower('%PathName'), '/gct/3. booking token applied/a) customer sample with booking ticket/') then
do something
end

this is not working, as long as ')' is in the string, any idea to bypass that? thanks

Re: problem with %PathName, %FileName in LUA

Posted: Wed Dec 02, 2020 3:18 pm
by FTP
OK, because some special characters like "( ) . % + - * ? [ ^ $" called magic characters in Lua language, you need to add a "%" before the magic character.

Code: Select all

if string.find(string.lower('%PathName'), '/gct/3. booking token applied/a%) customer sample with booking ticket/') then
...
end

Re: problem with %PathName, %FileName in LUA

Posted: Tue Dec 08, 2020 3:44 am
by JohnsonCat
lua is quite hard to understand...
if i get a path from %PathName, which contains special symbol like '()', how do I replace it before parse it to string.find or string.match function?
in other programming language, usually it's quite easy to force convert to string or other types...
Thank you.

Re: problem with %PathName, %FileName in LUA

Posted: Tue Dec 08, 2020 5:39 am
by JohnsonCat
the function i wrote:

function email(p1,p2,f,e)
if string.find(string.lower(p1), string.lower(p2)) then
c_SendMail(e,f.." is uploaded","File path is ["..p2..string.match(string.lower(p1), string.lower(p2)..'(.*)').."]","","SMTP")
end
end

email('%PathName','/path/','%FileName',"somebody@domain.com")

Re: problem with %PathName, %FileName in LUA

Posted: Tue Dec 08, 2020 4:58 pm
by FTP
OK, only the 2nd parameter of the function "string.find" needs to handle magic characters, please have a look at this document: https://riptutorial.com/lua/example/205 ... troduction" rel="nofollow