TJ_Tigger
11-03-2003, 11:52 AM
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
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