Folder.Find

table Folder.Find (

string StartFolder,

string Folder,

boolean Recurse = false,

function CallbackFunction = nil )

Example 1

ImageFolders = Folder.Find( _SourceFolder, "*Images*", true, ShowSearchProgress);

Searches for all folders inside the folder that the application is running, that contain "Images" in the name, and stores their paths in a table called ImageFolders. Since Recurse is true, the action will search inside subfolders. The function named ShowSearchProgress will be called whenever progress is made in the search operation.

Example 2

found = Folder.Find( Shell.GetFolder(SHF_MYDOCUMENTS),"Plant Data", false);
if (found) then
Dialog.Message("Found one!", "The first folder found was:" .. found[1]);
end

Searches for any folders inside the root of the user's My Documents folder that are named "Plant Data", and stores their paths in a table named "found." Then, the example tests that table to see if there were any folders stored in it (if there weren't, it would have been set to nil by the Folder.Find action), and if there are, puts up a message dialog to show the path to the first folder that was found.

Example 3

-- Set the callback function (used by action Folder.Find)
function FindCallBack(CurrentFolder)
-- Show the cancel button
StatusDlg.ShowCancelButton(true, "Cancel");
-- Set the status dialog title, message, and status text
StatusDlg.SetTitle("Searching . . . ");
StatusDlg.SetMessage("Please wait. Search is in progress.");
StatusDlg.SetStatusText("Current Folder: " .. CurrentFolder);
-- Check if the user pressed cancel
cancel = StatusDlg.IsCancelled();
if cancel then
-- Cancel was pressed, stop the current operation
return false;
else
-- Cancel was not pressed, continue
return true;
end
end




-- Set the drive to search
drive = "c:\\";
-- Set the folder to search for
folder = "windows";
-- Search the specified drive for folders named "windows"
-- Display the status dialog
StatusDlg.Show(0, false);
search_results = Folder.Find(drive, folder, true, FindCallBack);
--Check to see if an error occurred during the search. If it did, display the error message.
error = Application.GetLastError();
StatusDlg.Hide();
if error ~= 0 then
Dialog.Message("Error",_tblErrorMessages[error]);
else
-- If no directories were found, inform the user
if (search_results == nil) then
Dialog.Message("Notice", "There are no folders named '" .. folder .. "' on drive '" .. drive .. "'.");
-- If folders were found, display a dialog containing a list of their locations.
else
message = "A folder named '" .. folder .. "' was found at the following location(s):\r\n\r\n";
for index, path in pairs(search_results) do
message = String.Concat(message, path.."\r\n");
end
Dialog.Message("File Search Results", message, MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
end
end

This example uses the Folder.Find action to search for all instances of a particular folder on the user's hard drive. Once the search is complete, the user is presented a list of all the paths found. A callback function is used to customize the 'look' of the status dialog.

See also: Related Actions