If my memory is right, neither Finder nor System Events is able to treat this kind of filter.
You may start with :
property allFiles : {}
set thisFolder to path to desktop
set beginsList to {"#", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}
set theseItems to {}
tell application "Finder"
set my allFiles to items in thisFolder
repeat with aFile in my allFiles
if first character of (get name of aFile) is in beginsList then set end of theseItems to aFile as alias
end repeat
end tell
set my allFiles to {}
theseItems
or
property allFiles : {}
set thisFolder to path to desktop
set beginsList to {"#", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}
set theseItems to {}
tell application "System Events"
set my allFiles to disk items in thisFolder
repeat with aFile in my allFiles
try
if first character of (get name of aFile) is in beginsList then set end of theseItems to aFile as alias
end try
end repeat
end tell
set my allFiles to {}
theseItems
I inserted try / end try in the second script when I discovered that set maybe to name of aFile failed when aFile is a symlink.
I defined allFiles as a property to fasten the script.
If you aren’t reluctant to use ASObjC you may use :
use AppleScript version "2.4"
use framework "Foundation"
use scripting additions
on listFolder:POSIXPath
set beginsList to {"#", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}
set theseItems to {}
set fileManager to current application's NSFileManager's defaultManager()
set theNames to (fileManager's contentsOfDirectoryAtPath:POSIXPath |error|:(missing value)) as list
repeat with i from 1 to count of theNames
if character 1 of (item i of theNames) is in beginsList then
set end of theseItems to POSIXPath & item i of theNames
end if
end repeat
return theseItems
end listFolder:
its listFolder:(POSIX path of (path to desktop))
It’s seriously faster than the first ones.
I just had the idea to work upon names in vanilla AppleScript. The resulting scripts are really fast so here they are
property allNames : {}
set thisFolder to path to desktop
set beginsList to {"#", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}
set theseItems to {}
tell application "Finder"
set my allNames to name of items in thisFolder
set thisFolder to thisFolder as text
repeat with aName in my allNames
if first character of aName is in beginsList then set end of theseItems to (thisFolder & aName) as alias
end repeat
end tell
set my allNames to {}
theseItems
property allNames : {}
set thisFolder to path to desktop
set beginsList to {"#", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}
set theseItems to {}
tell application "System Events"
set my allNames to name of disk items in thisFolder
set thisFolder to thisFolder as text
repeat with aName in my allNames
if first character of aName is in beginsList then set end of theseItems to (thisFolder & aName) as alias
end repeat
end tell
set my allNames to {}
theseItems
Yvan KOENIG running El Capitan 10.11.4 in French (VALLAURIS, France) vendredi 8 avril 2016 17:50:23