AppleScript将文件移动到一个新文件夹并进行顺序命名。
创始人
2024-09-10 22:00:10
0

下面是一个使用AppleScript将文件移动到一个新文件夹并进行顺序命名的示例:

-- 设置目标文件夹路径
set targetFolder to (choose folder with prompt "选择目标文件夹")

-- 获取目标文件夹中的所有文件
set fileList to list folder targetFolder without invisibles

-- 设置新文件夹路径
set newFolderName to "新文件夹"
set newFolderPath to targetFolder & "/" & newFolderName

-- 创建新文件夹
tell application "Finder"
    if not (exists folder newFolderPath) then
        make new folder at folder targetFolder with properties {name:newFolderName}
    else
        display alert "错误" message "新文件夹已存在!"
        return
    end if
end tell

-- 对文件进行排序
set sortedList to my sortList(fileList)

-- 进行顺序命名并移动文件
repeat with i from 1 to count of sortedList
    set oldFilePath to (targetFolder & "/" & item i of sortedList) as text
    set newFileName to "文件" & i & ".txt"
    set newFilePath to (newFolderPath & "/" & newFileName) as text
    tell application "Finder"
        move file oldFilePath to folder newFolderPath with replacing
        set name of file newFilePath to newFileName
    end tell
end repeat

-- 排序函数
on sortList(listToSort)
    set sortedList to {}
    repeat until (count of listToSort) = 0
        set lowestItem to item 1 of listToSort
        repeat with itemValue in listToSort
            if itemValue comes before lowestItem then
                set lowestItem to itemValue
            end if
        end repeat
        set end of sortedList to lowestItem
        set listToSort to rest of listToSort
    end repeat
    return sortedList
end sortList

使用这个脚本,你可以选择一个目标文件夹,然后它会创建一个名为"新文件夹"的文件夹,并将目标文件夹中的文件按顺序命名后移动到新文件夹中。

相关内容

热门资讯

透视了解!德普之星透视辅助软件... 透视了解!德普之星透视辅助软件是真的吗,wepoker免费透视脚本,线上教程(切实真的有挂);德普之...
透视辅助!aapoker辅助工... 透视辅助!aapoker辅助工具免费下载,wepoker作弊方法,曝光教程(一直有挂)1、完成aap...
透视代打!aapoker辅助器... 透视代打!aapoker辅助器是真的吗,fishpoker透视,力荐教程(原先真的是有挂);aapo...
透视神器!hhpoker怎么开... 透视神器!hhpoker怎么开透视,wpk软件是正规的吗,2025新版(总是真的是有挂)1、完成hh...
透视私人局!红龙poker透视... 透视私人局!红龙poker透视工具,wpk有辅助器吗,细节揭秘(一向存在有挂);致您一封信;亲爱红龙...
透视挂!德普之星透视辅助插件,... 透视挂!德普之星透视辅助插件,wepoker辅助透视软件,必备教程(一直真的有挂)德普之星透视辅助插...
透视辅助!wepoker透视脚... 透视辅助!wepoker透视脚本,竞技联盟透视插件,专业教程(原生存在有挂);wepoker透视脚本...
透视游戏!wpk辅助工具下载,... 透视游戏!wpk辅助工具下载,wpk软件是正规的吗,第三方教程(本来真的是有挂);wpk辅助工具下载...
透视代打!wepoker辅助器... 透视代打!wepoker辅助器是真的的吗,pokemmo修改器手机版,新版2025教程(总是是有挂)...
透视透视!hhpoker透视脚... 透视透视!hhpoker透视脚本视频,德州机器人代打脚本,透明挂教程(先前真的有挂)1、这是跨平台的...