Applescript根据英国财政年度将文件分类到文件夹中

时间:2020-09-30 01:45:36

标签: macos applescript

我正在寻找一种基于英国财政年度(从4月6日至4月5日运行)移动文件的方法。 文件的命名方式为

2014-08-26_Asda_lunch.pdf
2016-03-20_Tesco_sationary.pdf

文件需要移动到已命名的文件夹,依此类推

FY 2014-15
FY 2015-16

只是想知道applescript / shell脚本或automator动作是否有助于实现这一目标。而且与榛树乌头的接口更好

预先感谢 我试图修改脚本

我的首要目标是正确的月份,然后尝试日期; 脚本的输出 文件2019-07-26_Tesco_stationary-> 2020财年(预计2019-20财年) 文件2019-03-15_Sainsbury-> 2019财年(预计2018-19财年) 请告知,在排序世界中添加日期的任何指针也有帮助 谢谢

set savedDelimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to {"-"}

tell application "Finder"
   set filename to name of theFile
end tell

set expenseYear to (first text item of filename) as number
set expenseMonth to (second text item of filename) as number
set expenseDate to (third text item of filename) as number

-- Get the last two characters of the Year
set AppleScript's text item delimiters to savedDelimiters
set lastTwoCharactersOfYear to (characters 3 thru 4 of (expenseYear as text))
set RoundedExpYear to (lastTwoCharactersOfYear as text) as number


if expenseMonth ≥ 4 then
   set LongString to expenseYear
   set ShortString to RoundedExpYear + 1
else
   set LongString to expenseYear - 1
   set ShortString to RoundedExpYear
end if


set returnText to "FY" & " " & LongString & "-" & ShortString

1 个答案:

答案 0 :(得分:0)

有很多解析日期的方法,但是由于您的格式始终是相同的(yyyy-mm-dd_xxxx),所以我使用了最简单的方法。在处理程序下面的脚本中,当您给参数输入文件名时,GetFY直接返回您要查找的格式“ FY YYYY-YYYY”:

set Fname to "2014-03-05_xxxx" -- value to test
set myfolder to GetFy(Fname)
log "myfolder=" & myfolder

on GetFy(Fname) -- return FY-(FY+1) based on Fname as YYYY-MM-DD_xxxxxx
    set myear to (text 1 thru 4 of Fname) as integer
    set mmonth to (text 6 thru 7 of Fname) as integer
    set mday to (text 9 thru 10 of Fname) as integer
    if mmonth < 4 then set Fy to myear - 1
    if mmonth = 4 then set Fy to myear - ((mday ≤ 5) as integer)
    if mmonth > 4 then set Fy to myear
    return "FY " & Fy & "-" & (Fy + 1)
end GetFy