用于更改文件名的Applescript

毛里兹

我想用applescript更改成千上万个文件名。

文件名都是以这种方式创建的:

第一部分-第二部分XX.xxx

其中XX为特定数字,.xxx为jpg或png扩展名。

我想简单地更改周围的部分,以使其变为:

secondPart-firstPart XX.xxx

我想出了这个办法,但是我的编码技能使我不满意。

tell application "Finder" to set aList to every file in folder "ImageRename"
set text item delimiters to {" - ", "."}
repeat with i from 1 to number of items in aList
    set aFile to (item i of aList)
    try
        set fileName to name of aFile
        set firstPart to text item 1 of fileName
        set secondPart to text item 2 of fileName
        set thirdPart to text item 3 of fileName
        set newName to secondPart & " - " & firstPart & "." & thirdPart
        set name of aFile to newName
    end try
end repeat

这仅适用于数字坚持第二部分。这样就变成了:

SecondPart XX-firstPart.xxx

如何使两个整数成为文本项定界符?

请帮助我,并一路教我:-)

jweaks

只需使用空格作为定界符并构建零件。编辑:在文本部分中留有空格。

tell application "Finder" to set aList to every file in folder "ImageRename"
set AppleScript's text item delimiters to " "
repeat with i from 1 to number of items in aList
    set aFile to (item i of aList)
    try
        set fileName to name of aFile
        set lastParts to text item -1 of fileName
        set wordParts to (text items 1 thru -2 of fileName) as string
        set AppleScript's text item delimiters to " - "
        set newName to {text item 2 of wordParts, "-", text item 1 of wordParts, lastParts}
        set AppleScript's text item delimiters to " "
        set name of aFile to (newName as string)
    end try
end repeat
set AppleScript's text item delimiters to ""

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

用于更改文件名的Applescript

来自分类Dev

更改文件名后,无法使用AppleScript移动文件

来自分类Dev

如何在复制 Applescript 之前更改文件名

来自分类Dev

更改文件名

来自分类Dev

if语句,用于打印已更改或新的文件名

来自分类Dev

Applescript选择文件,文件名

来自分类Dev

基于文件名的自动变量(Applescript?)

来自分类Dev

用于查看文件更改的Linux bash脚本->如何获取更改的文件名

来自分类Dev

Python文件名更改

来自分类Dev

更改海量文件名?

来自分类Dev

更改文件名,如何?

来自分类Dev

langast更改文件名

来自分类Dev

更改.fasta文件名

来自分类Dev

AppleScript中没有扩展名的文件名

来自分类Dev

AppleScript中没有扩展名的文件名

来自分类Dev

上传文件时更改文件名

来自分类Dev

applescript中文件名的国际化

来自分类Dev

使用Applescript打开带有转义字符的文件名

来自分类Dev

applescript小滴:在文件名中添加后缀

来自分类Dev

使用 Applescript 检查文件名是否相同

来自分类Dev

NSSavePanel无法更改文件名

来自分类Dev

在Xcode Project中更改文件名

来自分类Dev

更改文件名,而无需重写

来自分类Dev

bash:使用列表更改文件名

来自分类Dev

BigQuery:无法更改文件名

来自分类Dev

根据用户点击更改文件名

来自分类Dev

可以更改批准测试的文件名

来自分类Dev

PHP正在更改原始文件名

来自分类Dev

无法更改Zookeeper日志文件名