A basic question I’m sure for most, but I’m very new to Applescript. I use choose folder to display a dialog box where a user can select a folder full of files. The resulting list however contains file extensions. I’ve been trying to invent all kinds of ways to get rid of the file extensions downstream… is there a way to just capture a list of files without also capturing the extensions?
The result of choose folder is an alias of the chosen folder, not a list of the containing files
To get the list you want, you must parse the list of files and strip the name extension.
Something like this
choose folder
tell application "Finder" to set theFiles to files of result
repeat with i in theFiles
set contents of i to strip_name(i)
end repeat
on strip_name(f)
set {name:Nm, name extension:Ex} to info for (f as alias)
if Ex is missing value then return Nm
return text 1 thru ((count Nm) - (count Ex) - 1) of Nm
end strip_name
set fldr to (choose folder) -- for illustration
tell application "Finder"
set f to files of fldr
set baseNames to {}
repeat with aF in f
set {Nm, Ex} to {name, name extension} of aF
set end of baseNames to text 1 thru ((get offset of "." & Ex in Nm) - 1) of Nm
end repeat
end tell
Or, for a single file:
tell (info for (choose file)) to set basename to name's text 1 thru ((my (offset of ("." & name extension) in name)) - 1)
Thanks to everyone for the help! I can see I have a way to go yet along the scripting trail, but I’m hoping to accelerate the curve by reading everything I can here in the forum.