Hi all:
After searching in this forum and triyng myself to solve this doubt I got a partial solution to deleting folders that were found in previous searching to listbox (where is all the found folder located). The code is splitted in two parts, one code for searching folders that begings with the naming conventions "CAT-*" where * symbol is the pattern search for all folders that does it have the CAT part (those not having this pattern will be ignored and not included in listbox) in the button "search":
As for the second part code is the deletion section for those folders what begins at "CAT-xxxx" in another button called "Delete!":
The problem here is that listbox does not count correctly or not delete all folder found under that searching pattern, it makes me to have click again and again until all found folder gets deleted successfully. Where is my fault here? Why do not delete all folders if where found correctly in listbox. Another thing I tried is to make a while loop but i makes crash the app when is output to preview and execute. I use Win 7 x64 SP1 original and ams too version 8.3.
After searching in this forum and triyng myself to solve this doubt I got a partial solution to deleting folders that were found in previous searching to listbox (where is all the found folder located). The code is splitted in two parts, one code for searching folders that begings with the naming conventions "CAT-*" where * symbol is the pattern search for all folders that does it have the CAT part (those not having this pattern will be ignored and not included in listbox) in the button "search":
Code:
folderpath = Dialog.FolderBrowse("Please select a folder:", "d:\\"); StatusDlg.Show() tFolders = Folder.Find(folderpath, "CAT-*", true, nil);[COLOR="seagreen"]--search for folder with naming convention whose begins with "CAT-namefolder", eg: CAT-PhotoSports[/COLOR] StatusDlg.Hide() for i,v in pairs(tFolders) do tFiles = File.Find(v, "*.*", true, false, nil, nil) nSize = 0; if tFiles ~= nil then for x,y in pairs(tFiles) do nSize = nSize+File.GetSize(y); end end result = Dialog.TimedMessage("Notice", "Adding folder\r\n:"..v, 10, MB_ICONINFORMATION); ListBox.AddItem("ListBox1", v, v); end totalFound = ListBox.GetCount("ListBox1"); result = Dialog.Message("Notice", "Total found "..totalFound, MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1); Application.ExitScript();
Code:
ListBox.SelectItem("ListBox1", LB_ALLITEMS); local tbDeleteFiles = ListBox.GetSelected("ListBox1"); if(tbDeleteFiles) then for t, data in pairs (tbDeleteFiles) do local strPathFileToDelete = ListBox.GetItemData("ListBox1",tbDeleteFiles[t]); if(strPathFileToDelete ~= "") then File.Delete(tbDeleteFiles[t].."\\*.*", false, false, false, nil); Folder.DeleteTree(strPathFileToDelete, nil); local errno = Application.GetLastError(); if (errno ~= 0) then Dialog.Message("Error", _tblErrorMessages[errno], MB_OK, MB_ICONEXCLAMATION); else ListBox.DeleteItem("ListBox1", tbDeleteFiles[t]); end end end else Dialog.Message("Error", "Select an item from listbox", MB_OK, MB_ICONEXCLAMATION); end Dialog.Message("Notice", "Deletion successful", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
Comment