Apple Script- 搜索文件夹并重命名文件
创始人
2024-09-10 17:00:22
0

以下是一个使用AppleScript搜索文件夹并重命名文件的示例代码:

-- 设置要搜索的文件夹路径
set folderPath to choose folder with prompt "选择要搜索的文件夹"
-- 设置要搜索的文件名关键字
set keyword to "原文件名"
-- 设置要替换的文件名关键字
set replacement to "新文件名"

-- 定义一个处理文件的函数
on processFile(theFile)
    -- 获取文件名
    set fileName to name of theFile
    -- 检查文件名是否包含关键字
    if fileName contains keyword then
        -- 替换文件名中的关键字
        set newFileName to my replaceText(keyword, replacement, fileName)
        -- 设置新文件名
        set name of theFile to newFileName
    end if
end processFile

-- 定义一个替换文本的函数
on replaceText(find, replace, textString)
    set prevTIDs to text item delimiters of AppleScript
    set text item delimiters of AppleScript to find
    set textItems to every text item of textString
    set text item delimiters of AppleScript to replace
    set newText to textItems as string
    set text item delimiters of AppleScript to prevTIDs
    return newText
end replaceText

-- 遍历文件夹中的所有文件
tell application "Finder"
    set allFiles to every file of entire contents of folderPath
    repeat with aFile in allFiles
        -- 处理文件
        my processFile(aFile)
    end repeat
end tell

这段代码首先会弹出一个对话框,让您选择要搜索的文件夹。然后,它会遍历文件夹中的所有文件,并检查文件名是否包含关键字。如果文件名包含关键字,它将使用新的文件名替换关键字部分。

请注意,这段代码将在Finder应用程序中运行,因此确保不要启动其他可能干扰脚本执行的应用程序。

相关内容

热门资讯

辅助开挂!网易游戏辅助工具,德... 辅助开挂!网易游戏辅助工具,德州局透视脚本(透视)开挂辅助工具(有挂功能);超受欢迎的网易游戏辅助工...
分享个大家"潮友会鱼... 分享个大家"潮友会鱼虾蟹有没有挂辅助"开挂(透视)线上德州的辅助器是什么(有挂猫腻);大家肯定在之前...
开挂辅助!ios破解游戏盒子,... 开挂辅助!ios破解游戏盒子,sohoo poker辅助器(透视)开挂辅助神器(有挂细节);人气非常...
辅助开挂!微信小程序自动透视微... 辅助开挂!微信小程序自动透视微乐,聚星ai辅助工具激活码(透视)开挂辅助神器(有挂攻略);1、这是跨...
开挂辅助!赣牌圈靠谱吗,wej... 开挂辅助!赣牌圈靠谱吗,wejoker辅助器要钱玩吗(透视)开挂辅助下载(有挂教程);1、超多福利:...
总算了解"透视辅助器... 总算了解"透视辅助器(免费)"开挂(透视)hhpoker软件可以玩吗(有挂方法);最新版2026是一...
发现开挂!wepoker安装教... 发现开挂!wepoker安装教程,中至赣牌圈手机辅助,开挂(透视)辅助下载(真的有挂);致您一封信;...
正版开挂!德普之星透视辅助软件... 正版开挂!德普之星透视辅助软件,顺欣茶楼辅助视频,开挂(透视)辅助软件(证实有挂);顺欣茶楼辅助视频...
科普攻略"乐乐川南字... 科普攻略"乐乐川南字牌辅助器"开挂(透视)hhpoker辅助挂下载(有挂功能);软件透视开挂是一个全...
了解辅助!wepokerplu... 了解辅助!wepokerplus透视脚本免费,创思维激k是不是有挂,开挂(透视)辅助工具(真的有挂)...