好,所以我覺得這很簡單,但我忽略了很長的一段時間,經過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