When I “made a bit of complementary cleaning”, I missed the fact that you dropped a group of three instructions which I added in a preceding version.
They are :
set {tids, AppleScript’s text item delimiters} to {AppleScript’s text item delimiters, space}
set fileTypes to text items of fileTypes # WAS WRONGLY CODED
set AppleScript’s text item delimiters to tids
Without them your code check that the found extension is available in the STRING “flv avi mp4 mkv mov html”
This is why it accepts htm, h and would accept fl,f, av, a,mp, m, mk, ht, h.
With the three instructions the script no longer check that the found extension is available in the string but it search that it’s available in the list {“flv”, “avi”, “mp4”, “mkv”, “mov”, “html”}
So, I’m sure that you will get better results with :
(*
http://macscripter.net/viewtopic.php?id=44118
Get user list of file extensions to search for in Choose Folder
Search all subfolder levels of the chosen folder and return all files whose extension is on the user list
Output to clipboard as list, including folder hierarchy
*)
property fileTypes : {}
property listAllFlag : false
property fileCount : 0
set fileTypes to text returned of (display dialog "Enter any number of file extensions, separated by a single space, to be included on the file list for the chosen folder. Leave empty to list all files." default answer "flv avi mp4 mkv mov html")
-- Here, fileTypes is the string "avi mp4 mkv flv mov html"
set {tids, AppleScript's text item delimiters} to {AppleScript's text item delimiters, space}
set fileTypes to text items of fileTypes # WAS WRONGLY CODED
set AppleScript's text item delimiters to tids
-- Here, fileTypes is the list {"flv", "avi", "mp4", "mkv", "mov", "html"}
set listAllFlag to fileTypes = "" -- if no extensions entered then list all files
if listAllFlag then
set theFolder to choose folder with prompt "Choose folder to list all its files"
else
set theFolder to choose folder with prompt "Choose folder to list its files with the entered file extensions"
end if
set beg to current date
set fileCount to 0
set theListing to my do_subfolders(theFolder, "", "")
if fileCount > 0 then
set the clipboard to theListing
display dialog "Done in : " & ((current date) - beg) & " seconds" & return & fileCount & " files were found and left on the Clipboard"
else
set noneFound to " No files were found with the entered extensions"
set the clipboard to noneFound --else the Clipboard still retains old data which could look like a newly returned theListing
display dialog "Done in : " & ((current date) - beg) & " seconds" & return & noneFound
end if
on do_subfolders(theFolder, name_prefix, theListing)
tell application "System Events"
set filesAvailable to every file in theFolder
set file_list to {}
repeat with afile in filesAvailable
try
if listAllFlag then --no file extensions were entered so list all files
set end of file_list to contents of afile
set fileCount to fileCount + 1
else --at least one file extension was entered so include this file if its extension is on the list
if (name extension of afile) is in fileTypes then
set end of file_list to contents of afile
set fileCount to fileCount + 1
end if
end if
end try
end repeat
if file_list is not {} then
if name_prefix is not "" then set theListing to theListing & name_prefix & (name of theFolder) & return
repeat with this_file in file_list
set theListing to theListing & name_prefix & " " & (name of this_file) & return
end repeat
set theListing to theListing & return
end if
set folder_list to every folder in theFolder
repeat with this_subfolder in folder_list
set theListing to my do_subfolders(this_subfolder, " " & name_prefix, theListing)
end repeat
end tell
return theListing # May be better to return AFTER telling System Events explicitly that we no longer speak to it.
end do_subfolders
For safe, I edit also my preceding message.
Yvan KOENIG running El Capitan 10.11.1 in French (VALLAURIS, France) vendredi 4 décembre 2015 17:03:13