Applescript: Get filenames in folder without extension

前端 未结 8 1794
忘掉有多难
忘掉有多难 2020-12-11 03:36

I can get the names of all files in a folder by doing this:

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

相关标签:
8条回答
  • 2020-12-11 04:17

    For a single file I found the answer here, copied below.

    set theFileName to "test.jpg"
    set thePrefix to text 1 thru ((offset of "." in theFileName) - 1) of theFileName
    
    0 讨论(0)
  • 2020-12-11 04:20

    Based on Lauri Ranta's nice solution, which works for extensions that Finder doesn't know about:

    set delims to AppleScript's text item delimiters
    set AppleScript's text item delimiters to "."
    set myNames to {}
    tell application "Finder"
        set myFiles to name of every file of (path to Desktop)
        repeat with myfile in myFiles
            set myname to name of file myfile
            if myname contains "." then set myname to (text items 1 thru -2 of myname) as text
            set end of myNames to myname
        end repeat
    end tell
    set AppleScript's text item delimiters to delims
    return myNames
    
    0 讨论(0)
提交回复
热议问题