Applescript - рекурсивный пошаговый просмотр каталогов - PullRequest
0 голосов
/ 31 января 2019

Я нашел похожие решения, подобные этому:

property theOpenFile : missing value

tell application "Finder" to set theSel to selection
if theSel is not {} then
    set pathToYourTextFile to (path to desktop folder as string) & "SampleTextFile2.txt"
    set theOpenFile to open for access file (pathToYourTextFile as string) with write permission
    repeat with aItem in theSel
        tell application "Finder" to class of aItem is folder
        if the result then my getFilesIn(aItem) -- aItem is a folder
    end repeat
    close access theOpenFile
end if

on getFilesIn(thisFolder)
    tell application "Finder" to set theseFiles to files of thisFolder as alias list
    repeat with thisFile in theseFiles
        set f to thisFile as string
        set pathLength to length of f
        if pathLength > 255 then my writeToFile(f)
    end repeat
    tell application "Finder" to set theseSubFolders to folders of thisFolder
    repeat with tSubF in theseSubFolders
        my getFilesIn(tSubF) -- call this handler (recursively through this folder)
    end repeat
end getFilesIn

on writeToFile(t)
    write (t & return) to theOpenFile starting at eof
end writeToFile

Все они работают со ссылкой на файл в формате псевдонима.Как я понимаю, я не могу изменить имя файла оригинала в этом случае или удалить его и т. Д., И это то, что я хочу сделать.

Я прав?Если да, что еще я могу сделать?

1 Ответ

0 голосов
/ 31 января 2019

Вы можете переименовывать и удалять файлы, Finder может обрабатывать alias спецификаторы

repeat with thisFile in (get theseFiles) -- you need get to capture the reference list
    set f to thisFile as string
    set pathLength to length of f
    if pathLength > 255 then my writeToFile(f)
    tell application "Finder" to set name of thisFile to "foo.txt"
    -- or 
    tell application "Finder" to delete thisFile
end repeat

или вместо alias вы можете использовать Finder file спецификаторы

repeat with thisFile in (get theseFiles)
    set f to thisFile as string
    set pathLength to length of f
    if pathLength > 255 then my writeToFile(f)
    tell application "Finder" to set name of file f to "foo.txt"
    -- or 
    tell application "Finder" to delete file f
end repeat
...