Page 1 of 1

search text result

Posted: Wed Mar 18, 2015 10:38 am
by gepponline
Hi!
I have to search in a text if there is a certain string.
In details I have to check if a file is in a folder.
So i get the list of files with "the files"

Now searching the web i found the "find" command, but it seems that it draw a box around a text instead of answer if is it found or not.

How should i do to know if the text is present or not?


OT: I found in the dictionary that every command is well explained but not the results.
You know, you can find for every command what it does but not where it place its "result".
I think that more than Syntax, summary and examples, every command should have an "OUTPUT" section to tell the user what and where does the command/function give back.

Re: search text result

Posted: Wed Mar 18, 2015 12:47 pm
by magice
Look up foundText and foundLine. :D

Re: search text result

Posted: Wed Mar 18, 2015 1:44 pm
by gepponline
beeing a search of a file in a folder, I'm searching in "the files" is correct to write something like this?

Code: Select all

 set the defaultFolder to specialFolderPath("documents")
   put the files into tFileList
   find "censimentofiliere.txt" in tFileList
   if the foundText is "censimentofiliere.txt" then   

Re: search text result

Posted: Wed Mar 18, 2015 1:46 pm
by Klaus
Hi Geppo,

since the FIND command is intended to give a visual feedbak (square around the found word/chunk)
this should be used for finding things inside of fields in LC.

When searching for strings in text files or even fielnames in file listings, using "lineoffset" is much more efficient!

Code: Select all

set the defaultFolder to specialFolderPath("documents")
put the files into tFileList
put lineoffset("censimentofiliere.txt",tFileList) into tFoundLine
if tFoundLine = 0 then
  ## not found
else
  file is existent in listing
end if

Best

Klaus

Re: search text result

Posted: Wed Mar 18, 2015 2:34 pm
by gepponline
...Klaus..my personal trainer :)

thank you very very much :)