2013-11-28 94 views
0

我剛剛拿到help以獲取所選文件夾的文件名。applescript獲取給定路徑的文件名

tell application "Finder" 
name of files of folder (choose folder) -- names of files 
end tell 

但是,我不能得到這個工作對於給定的路徑,像這樣的

set myfile to name of files of folder "~/Downloads/test/" 

我周圍有很多與POSIX路徑和其它打過,但我不能得到這個工作。您能否再次幫助我,謝謝。

回答

3

這應該做的伎倆:

tell application "System Events" 

    set downloadsFolder to path to downloads folder as text 
    -- display dialog downloadsFolder 

end tell 

tell application "Finder" 

    set myFileNames to name of files of folder (downloadsFolder & "test:") 
    log myFileNames 

end tell 

此外:

set thisLocation to "/Volumes/Data/" 

tell application "Finder" 

    set myFileNames to name of files of folder (thisLocation as POSIX file) 
    log myFileNames 

end tell 
+0

我不能得到這個工作外部體積,例如,設置downloadsFolder到路徑「卷:數據: 「作爲文本 – kuruvi

+0

看到我的補充。 – 2013-11-29 02:32:27

+0

順便說一句編輯器有內置的代碼片段,CTRL-CLICK到腳本中來查看它們。 – 2013-11-29 02:50:48