Page 1 of 1
check lines of a text file
Posted: Mon Nov 10, 2008 8:46 am
by alemrantareq
hi everybody, i need to check two lines i.e. "open=test.exe" and "Go to my folder" written into a text file located in desktop folder. If these lines exist, the application will open else exit showing a message. what will be script to do it in simple? pls, help me...Thanks
Posted: Mon Nov 10, 2008 9:25 am
by SparkOut
Check the "offset" variants in the dictionary.
lineOffset sounds like it's appropriate for your use.
If you read the text file into a variable before testing, you could use
Code: Select all
If (lineOffset ("open=test.exe", theFile) is zero) or (lineOffset ("Go to my folder", theFile) is zero) then
--exit
else
--launch
end if
Alternatively you could "open" the file for reading and "read from file" line by line and test each line that's read, but it's probably quicker and simpler with less overall overhead to read the entire file into a variable first.
Posted: Mon Nov 17, 2008 8:00 am
by alemrantareq
Dear SparkOut,
Thanks for your reply. I've tried it with lineoffset function. But it doesn't work. For example, I've a text file "test.txt" in my desktop. now, i made the script:
put specialfolderpath("desktop") & "/test.txt" into theFile
if lineOffset("open=test.txt", theFile) is zero then
answer "Line not found"
else
answer "Line was found"
end if
Is the script wrong? I've also tried wordOffset function in leau of lineOffset function, but failed. pls, help me...
Posted: Mon Nov 17, 2008 9:00 am
by SparkOut
To get the file into the tFile variable in the first place you need to get it from a url (which can be a file location on your computer). What you have so far is just testing the
path/name of the file for the string. To read the file into a variable, try
Code: Select all
put specialfolderpath("desktop") & "/test.txt" into thePath
put url ("file:" & thePath) into theFile
if lineOffset("open=test.txt", theFile) is zero then
answer "Line not found"
else
answer "Line was found"
end if