hi:
I want search files by filename with two keywords, how can I do it?
i.e:I want to search a file whose name contains 2005 and crach.
Please help me!
THX
Professional Software Development Tools
hi:
I want search files by filename with two keywords, how can I do it?
i.e:I want to search a file whose name contains 2005 and crach.
Please help me!
THX
Here is a very simple example. I would recommend you bullet-proof the Input Object data checks (say, trim off the spaces from either side, etc. etc.) before using this is a critical project.
Here is the main code chunk:
Code:-- Was the Enter key pressed? If so, continue on... if e_Key == 13 then strSearch1 = Input.GetText("Input1") strSearch2 = Input.GetText("Input2") -- Continue on if both Input Objects have data in them... if strSearch1 ~= "" and strSearch2 ~= "" then -- Get the file paths for all of the files in the AutoPlay/Docs (project) folder tblFiles = File.Find("AutoPlay//Docs", "*.txt", false, true, nil, nil) -- For each path in the table of paths generated do the following... for index,value in tblFiles do -- First, set a variable to hold one path out of the table (as we go through the table then we can work with just one file's path) path = String.SplitPath(value) -- Next, compare the data entered in the Input Objects to see if there is a match (case-insensitive) with any of the file names -- The break;'s are in place so as to allow the script to continue on after a match (or lack of) is found if String.CompareNoCase(strSearch1, path.Filename) == 0 or String.CompareNoCase(strSearch2, path.Filename) == 0 then is_found = true break; else is_found = false break; end end -- Give feedback to the end-user after we have checked for any file name matches against the two search terms if (is_found) then Dialog.Message("Results...", "There was a match with one of your search terms! ", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1) else Dialog.Message("Results...", "No match found!", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1) end end -- Reset Input Objecst (to nothing) Input.SetText("Input1", "") Input.SetText("Input2", "") -- Set focus to the first Input Object Page.SetFocus("Input1") end
Intrigued
THX a lot!![]()
but if I have not only one file to show, how to deal with it?
Do you mean to say you want to search for more than one file type? In Intrigueds example it will find all the txt files in the specified directory and your search will take place in respect to all of those files. If you want more than one file type perform multiple File searches and then either run your search against all of those tables or combine all of your tables into one table and search that one table.Originally Posted by airpumpkin
TJ-Tigger
"A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
"Draco dormiens nunquam titillandus."
Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine
thx Tiger.
I meant that I have not only one file matches the two keywords. in Worm's reply, it shows that only one file is shown to the user.
Thanks for elaborating. Try thisOriginally Posted by airpumpkin
Code:-- Was the Enter key pressed? If so, continue on... if e_Key == 13 then strSearch1 = Input.GetText("Input1") strSearch2 = Input.GetText("Input2") -- Continue on if both Input Objects have data in them... if strSearch1 ~= "" and strSearch2 ~= "" then -- Get the file paths for all of the files in the AutoPlay/Docs (project) folder tblFiles = File.Find("AutoPlay//Docs", "*.txt", false, true, nil, nil) -- For each path in the table of paths generated do the following... --Build table to store found file in tbFoundFile = {}; for index,value in tblFiles do -- First, set a variable to hold one path out of the table (as we go through the table then we can work with just one file's path) path = String.SplitPath(value) -- Next, compare the data entered in the Input Objects to see if there is a match (case-insensitive) with any of the file names -- The break;'s are in place so as to allow the script to continue on after a match (or lack of) is found if String.CompareNoCase(strSearch1, path.Filename) == 0 or String.CompareNoCase(strSearch2, path.Filename) == 0 then Table.Insert(tbFoundFiles, Table.Count(tbFoundFiles) +1, value); end end -- Give feedback to the end-user after we have checked for any file name matches against the two search terms --check to see if the table has items in it if Table.Count(tbFoundFiles) > 0 then is_found = true end if (is_found) then Dialog.Message("Results...", "There was a match with one of your search terms! ", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1) else Dialog.Message("Results...", "No match found!", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1) end end -- Reset Input Objecst (to nothing) Input.SetText("Input1", "") Input.SetText("Input2", "") -- Set focus to the first Input Object Page.SetFocus("Input1") end
TJ-Tigger
"A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
"Draco dormiens nunquam titillandus."
Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine