好,所以我觉得这很简单,但我忽略了很长的一段时间,经过2个小时的尝试,我在寻求帮助的同时,仔细考虑了更多。在苹果脚本中,我如何比较两个不同长度的列表?
在applescript中,我试图比较两个排序的列表,但长度不一样。我想要做的是获取文件夹中所有文件的列表,将每个文件筛选到MP4或MTS中,并列出每个文件的列表,然后比较两个确切的位置以找出哪些MTS文件没有有一个MP4副本,然后将MTS文件名添加到新的列表中,以便稍后在查找器中选择。我为totalFiles变量使用了一个占位符,直到它准备在现实世界中使用。在占位符中,结果应该只是“6534-Seasons.MTS”,因为没有MP4可以使用它。相反,它会崩溃,因为它不能在MP4列表中搜索那么远,因为它没有MTS那么多。在这种情况下,没有MTS将不会有MP4。
我已经得到了尽可能多的创建两个单独的列表,并比较它们之前发现我的重复循环中断,因为MP4的数量将大多数时间低于MTS文件的数量。这里是我所拥有的
--Look for files that don't have .MP4, find their MTS counterpart.
set totalFiles to {"41 - The words.MTS", "41 - The words.MP4", "445 - Life on the rails.MTS", "445 - Life on the rails.mp4", "6354-Seasons.MTS"} -- List of all files in folder
set clickList to {}
--log totalFiles
--log vidlist
on siftfiles(totalFiles)
--Sift through everything and find mp4s, then add to a list. Do the same for MTS but add separately.
set MTSlist to {}
set MP4list to {}
repeat with vidname in totalFiles
if (vidname contains ".MP4") or (vidname contains ".mp4") then
set end of MP4list to vidname as string
end if
if vidname contains ".MTS" then
set end of MTSlist to vidname as string
end if
end repeat
set returnlist to {MP4list, MTSlist}
return returnlist
end siftfiles
set MP4slist to item 1 of siftfiles(totalFiles)
set MTSlist to item 2 of siftfiles(totalFiles)
--siftfiles(totalFiles)
--MP4slist
--Compare the two lists
set clickList to {}
set i to 1
repeat with thename in MTSlist
set MP4name to characters 1 thru -5 of item i of MP4slist as string
set MTSname to characters 1 thru -5 of item i of MTSlist as string
if MP4name is not MTSname then
set end of clickList to (thename as string)
end if
set i to i + 1
end repeat
clickList
谢谢。
我也改变了我在这个问题的方法几次,所以也许有比比较它们更好的方法吗?
dammit @jweaks你击败了我不到一分钟! :-) – CRGreen