Applescript: Получить имена файлов в папке без расширения

Я могу получить имена всех файлов в папке, выполнив следующие действия:

tell application "Finder"
    set myFiles to name of every file of somePath
end tell

Как я могу изменить строки в myFiles , чтобы они не включали расширение файла?

Я мог бы, например, получить {"foo.mov", "bar.mov"} , но хотел бы иметь {"foo "," bar "} .


Текущее решение

На основе принятого ответа я придумал приведенный ниже код. Сообщите мне, можно ли как-то сделать его более чистым или более эффективным.

-- Gets a list of filenames from the
on filenames from _folder

    -- Get filenames and extensions
    tell application "Finder"
        set _filenames to name of every file of _folder
        set _extensions to name extension of every file of _folder
    end tell

    -- Collect names (filename - dot and extension)
    set _names to {}
    repeat with n from 1 to count of _filenames

        set _filename to item n of _filenames
        set _extension to item n of _extensions

        if _extension is not "" then
            set _length to (count of _filename) - (count of _extension) - 1
            set end of _names to text 1 thru _length of _filename
        else
            set end of _names to _filename
        end if

    end repeat

    -- Done
    return _names
end filenames

-- Example usage
return filenames from (path to desktop)
7
задан Svish 26 November 2010 в 14:30
поделиться