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

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

相关内容

热门资讯

程序员教你“hhpoker一直... 是一款专注玩家量身打造的游戏记牌类型软件,在这款游戏中我们可以记录下每张牌的数量以便更好的进行发挥。...
必备攻略“wepoker辅助是... wepoker辅助是一款专注玩家量身打造的游戏记牌类型软件,在wepoker辅助这款游戏中我们可以记...
玩家必看科普“德州hhpoke... >>您好:确实是有挂的,很多玩家在这款游戏中打牌都会发现很多用户的牌特别好,总是好牌,而且好像能看到...
透视免费“约局吧开挂神器是真的... 透视免费“约局吧开挂神器是真的吗”开挂(透视)辅助脚本(普及教程有挂助手)1、下载安装好,进入游戏主...
重大发现“hhpoker的辅助... 无需打开直接搜索微信:136704302本司针对手游进行,选择我们的四大理由: 1、软件助手是一款功...
重大发现“佛手在线大菠萝智能辅... 重大发现“佛手在线大菠萝智能辅助器”开挂(透视)辅助神器(攻略教程有挂详细)>>您好:软件加1367...
揭秘几款“wepoker辅助器... 揭秘几款“wepoker辅助器”开挂(透视)辅助插件(切实教程有挂解密)wepoker辅助器ai黑科...
一起来讨论“we poker辅... 开挂教程视频分享装挂详细步骤在当今的网络游戏中,作为一种经典的娱乐方式,吸引了无数玩家的参与。尤其是...
盘点一款“wejoker开挂”... 盘点一款“wejoker开挂”开挂(透视)辅助工具(2026新版总结真的有挂)《详细加薇136704...
透视透视挂“wepoker辅助... wepoker辅助开挂教程视频分享装挂详细步骤在当今的网络游戏中,wepoker辅助作为一种经典的娱...