Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Applescript 在递归处理中钻得更深_Applescript - Fatal编程技术网

Applescript 在递归处理中钻得更深

Applescript 在递归处理中钻得更深,applescript,Applescript,我有一个三层的文件夹,每层包含大量的文件。我可以通过下面的脚本深入到两个层次,但是第三个层次带来了一些挑战。有没有人能给我一些指导,告诉我怎样才能更深一层?使用python或其他语言是不可接受的,因为我正在尝试了解如何使用AppleScript set sourceFolder to (choose folder) tell application "Finder" my changeFileNameCase(sourceFolder, "upper") repeat with

我有一个三层的文件夹,每层包含大量的文件。我可以通过下面的脚本深入到两个层次,但是第三个层次带来了一些挑战。有没有人能给我一些指导,告诉我怎样才能更深一层?使用python或其他语言是不可接受的,因为我正在尝试了解如何使用AppleScript

set sourceFolder to (choose folder)

tell application "Finder"
    my changeFileNameCase(sourceFolder, "upper")
    repeat with subFolder in (get every folder of folder sourceFolder)
        my changeFileNameCase(subFolder as alias, "upper")

        #This Is No Good
        repeat with theFolder in (get every folder of folder subFolder)
            my changeFileNameCase(theFolder, "upper")
        end repeat

    end repeat
end tell

on changeFileNameCase(targetFolder, caseToSwitchTo)
    tell application "Finder"
        set fileList to every file of folder targetFolder
        repeat with theFile in fileList
            set oldName to name of theFile
            set newName to my changeCaseOfText(oldName, caseToSwitchTo)
            set the name of theFile to newName
        end repeat
    end tell
end changeFileNameCase

要使处理程序递归,必须获取文件夹的所有项,并检查每个项的类

  • 如果类是
    文件夹
    调用传递文件夹的处理程序
  • 如果类是
    文件
    重命名它


啊,我几乎知道你要做什么了,但是看起来如果Iteem是一个文件夹,这会重命名文件夹,因为我只想重命名文件。我假设那是我必须建立子文件夹列表的地方?如果item是文件夹-生成子文件夹列表?否,如果该项是文件夹,则递归调用处理程序。级别的数量无关紧要。第二看,我看到处理程序正在调用自己。总之,它抛出了一个错误,称自己为error“Finder有一个错误:无法继续changeFileNameCase。”数字-1708我将花一些时间挑选这个公寓。我的坏,有一个
my
丢失了。我更新了答案。我自己刚捕捉到,非常有趣的方法。我喜欢。
set sourceFolder to (choose folder)
changeFileNameCase(sourceFolder, "upper")

on changeFileNameCase(targetFolder, caseToSwitchTo)
    tell application "Finder"
        set theList to every item of targetFolder
        repeat with i from 1 to count theList
            set theItem to item i of theList
            if class of theItem is folder then
                my changeFileNameCase(theItem, caseToSwitchTo)
            else
                set oldName to name of theItem
                set newName to my changeCaseOfText(oldName, caseToSwitchTo)
                set name of theItem to newName
            end if
        end repeat
    end tell
end changeFileNameCase