Indigo Rose Software

Professional Software Development Tools

 
Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 2005
    Posts
    8

    help!searching files by filename with two keywords.

    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

  2. #2
    Join Date
    Dec 2003
    Location
    Location! Location!
    Posts
    6,137
    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
    Attached Files
    Intrigued

  3. #3
    Join Date
    Apr 2005
    Posts
    8
    THX a lot!

    but if I have not only one file to show, how to deal with it?

  4. #4
    Join Date
    Sep 2002
    Location
    Sol 3
    Posts
    3,160
    Quote Originally Posted by airpumpkin
    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.
    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

  5. #5
    Join Date
    Apr 2005
    Posts
    8
    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.

  6. #6
    Join Date
    Sep 2002
    Location
    Sol 3
    Posts
    3,160
    Quote Originally Posted by airpumpkin
    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 this

    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

Similar Threads

  1. method to index/compare user's files for update?
    By intel352 in forum Setup Factory 6.0
    Replies: 0
    Last Post: 01-15-2003, 03:08 PM
  2. Replies: 2
    Last Post: 01-13-2003, 01:00 AM
  3. INFO: Why Files are Renamed in the DATA Folder
    By Support in forum AutoPlay Media Studio 4.0 Examples
    Replies: 0
    Last Post: 10-24-2002, 03:36 PM
  4. HOWTO: "Hide" Externally Referenced Files
    By Support in forum AutoPlay Media Studio 4.0 Examples
    Replies: 0
    Last Post: 10-23-2002, 03:19 PM
  5. HOWTO: Remove Files that were Installed by a Patch or Alternate Source
    By Support in forum Setup Factory 6.0 Knowledge Base
    Replies: 0
    Last Post: 09-24-2002, 09:49 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts