Indigo Rose Software
  #1  
Old 11-03-2003
TJ_Tigger's Avatar
TJ_Tigger TJ_Tigger is offline
Indigo Rose Customer
 
Join Date: Sep 2002
Location: Sol 3
Posts: 3,188
Find.File not failing

I tried to follow the examples in the help manual on using the Find.File action and when there was not a file found it was still showing up as a success. I could not get the following examples to work for me.

From example 2 in the help guide:
found = File.Find( Shell.GetFolder(SHF_MYDOCUMENTS), true, false, "*.pdf");
if (found) then
Dialog.Message("Found one!", "The first PDF file found was:" .. found[1]);
end

From example 4 in the help guide:
-- Gets the path to the user's My Documents folder.
my_docs_path = Shell.GetFolder(SHF_MYDOCUMENTS);

-- Check to see if the My Documents folder detection was successful.
if (Application.GetLastError() == 0)then

-- Search the user's My Documents folder for the file "Data.ini".
search_results = File.Find(my_docs_path, "Data.ini", true, false, nil);

--Check to see if an error occurred during the search. If it did, display the error message.
error = Application.GetLastError();
if error ~= 0 then
Dialog.Message("Error",_tblErrorMessages[error]);
else

-- If no files were found, notify the user.
if (search_results == nil) then
Dialog.Message("Notice", "Data.ini was not found in your My Documents folder.");

-- If files were found, display a dialog containing a list of their locations.
-- Also ask for deletion confirmation.
else
message = "Data.ini was found in the following location(s). Click OK to delete the file(s):\r\n\r\n";
for index, path in search_results do
message = String.Concat(message, path.."\r\n");
end
proceed = Dialog.Message("File Search Results", message, MB_OKCANCEL, MB_ICONQUESTION, MB_DEFBUTTON1);

-- If the user clicked OK, delete all of the files found.
if proceed == IDOK then

-- Delete each file found in the search.
for index, path in search_results do
File.Delete(path, false, false, false, nil);

-- Check to see if any errors occurred during the deletion.
if (Application.GetLastError() ~= 0) then
Dialog.Message("Error", "The file located at: "..path.." could not be deleted.");
end
end
end
end
end
end

What I ended up doing was to check to see if the variable that was returned was nil or not.

Here is my code see the red line below:
ssfolder = Dialog.FolderBrowse("Select a folder that contains pictures.", _DesktopFolder);
if (ssfolder ~= "CANCEL") and (ssfolder ~= "") then
subfolders = Dialog.Message("Recurse Subfolders", "Do you want to include subfolders", MB_YESNO, MB_ICONQUESTION, MB_DEFBUTTON2)
if (subfolders == IDYES) then
subfolder = true
else
subfolder = false
end
pic_table = File.Find(ssfolder, "*.jpg", subfolder, false, nil);
--error = Application.GetLastError();
if (pic_table == nil) then
Dialog.Message("Error", "There were no pictures in the selected Directory. Please select a directory that contains .JPG images", MB_OK, MB_ICONEXCLAMATION, MB_DEFBUTTON1)
dirselect = "NO";
ListBox.DeleteItem("ListBox1", LB_ALLITEMS);
visible = Image.IsVisible("Image1")
if (visible) then
Image.SetVisible("Image1", false);
Image.SetVisible("Image2", false)
end
else
pic_count = Table.Count(pic_table);
ctr = 1;
GetImage(500,375)
Image.SetVisible("Image1", true);
Image.SetVisible("Image2", true);
dirselect = "YES";
ListBox.DeleteItem("ListBox1", LB_ALLITEMS);
for i,pic in pic_table do
ListBox.AddItem("ListBox1", "Image" .. i, pic);
end
end
else
Dialog.Message("Notice", "You need to select a directory first.", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
dirselect = "NO";
ListBox.DeleteItem("ListBox1", LB_ALLITEMS);
visible = Image.IsVisible("Image1")
if (visible) then
Image.SetVisible("Image1", false);
Image.SetVisible("Image2", false)
end
end
Reply With Quote
  #2  
Old 11-03-2003
Darryl's Avatar
Darryl Darryl is offline
Indigo Rose Staff Member
 
Join Date: Jul 2001
Location: Indigo Rose Software
Posts: 1,602
In the docs for this action, if no files are found, nil is returned. In this case, the action succeeded, it's just that no files were found. So that wouldn't be a failure as far as the action is concerned.

However nil can also be returned if some sort of error occurs in the action, for example the folder wasn't valid or something like that.

However as you say, in my tests, I wasn't able to generate an error code. I'll have to speak to the developers about possible return codes for that action, but it's my belief that if you have an invalid search folder for example, that an error code should be returned. I'll look into this.

I just want to make sure that you are not expecting an error code if no files were found, because in this action, that is not considered a failure. It actually succeeded in what it was trying to do.

Please let me know if I was totally wrong in my interpretation or whether that is what you were expecting.
Reply With Quote
  #3  
Old 11-03-2003
TJ_Tigger's Avatar
TJ_Tigger TJ_Tigger is offline
Indigo Rose Customer
 
Join Date: Sep 2002
Location: Sol 3
Posts: 3,188
I guess I was expecting some sort of error or indication other than "nil" to be returned when no files were found. I see your point that the function worked the way it was supposed to work so there was not actually an error, just not the result I was looking for. I was expecting to see something like Table empty or table could not be created because no files were found.

Maybe I was confused in reading the help file because it seems like they were doing what I was trying to do at first, which was if there were no files found, get an error code and then act upon that error. No where in the examples for the File.Find action does it show what I was trying to do. They only tested the table as follows:

found = File.Find( Shell.GetFolder(SHF_MYDOCUMENTS), true, false, "*.pdf");
if (found) then
Dialog.Message("Found one!", "The first PDF file found was:" .. found[1]);
end

-- Gets the path to the user's My Documents folder.
my_docs_path = Shell.GetFolder(SHF_MYDOCUMENTS);

-- Check to see if the My Documents folder detection was successful.
if (Application.GetLastError() == 0)then

-- Search the user's My Documents folder for the file "Data.ini".
search_results = File.Find(my_docs_path, "Data.ini", true, false, nil);

--Check to see if an error occurred during the search. If it did, display the error message.
error = Application.GetLastError();
if error ~= 0 then
Dialog.Message("Error",_tblErrorMessages[error]);
else

Maybe it was my misinterperation of the way I should be doing it and the way my mind was thinking how it should be done. Oh well I figured it out. I wanted to post it here just in case you wanted to include another example in the help.

Tigg
Reply With Quote
  #4  
Old 11-03-2003
Darryl's Avatar
Darryl Darryl is offline
Indigo Rose Staff Member
 
Join Date: Jul 2001
Location: Indigo Rose Software
Posts: 1,602
Yes, we definitely don't want to confuse users with the examples, so anything that is thought of as confusing should be addressed.

However there is a line in that example 4 that does exactly what you were doing. Below the error checking for the File.Find action, you will also see the lines:

-- If no files were found, notify the user.
if (search_results == nil) then
Dialog.Message("Notice", "Data.ini was not found in your My Documents folder.");

The thing is, the Application.GetLastError action must be placed right after the action in order to get the error code.

So basically it was first making sure no error occurred. If there was no error, check the results of the Find action. If no results were found, then display the appropriate message.

I hope that makes sense.

In reality most of the time the developer will be in control over what is being passed into the actions, therefore real "errors" will not often arise and it is probably sufficient to just check the result of the action. However in some cases, you may not have control over what is passed into the action. That is where the error checking really comes into play and you may even need to know the exact error code that is returned to respond appropriately.

If the example still doesn't make sense, please let me know. However I believe it did address what you explained. However I believe I was the one who wrote it, so I may be a casualty of tunnel vision on this one.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



All times are GMT -6. The time now is 01:04 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright © 2000 - 2009 Indigo Rose Corporation. All rights reserved.
Indigo Rose Software