2017-03-01 2 views
0

좋아, 이건 단순하다고 느낀다. 그러나 나는 오랜 일들을 간과하고있다. 그리고 스스로 시도하기 위해 2 시간이 지난 후에, 나는 그것을 더 많이 검토하는 동안 도움을 요청하고있다.AppleScript에서 동일한 길이가 아닌 두 목록을 비교하려면 어떻게해야합니까?

나는 applescript에서 2 개의 목록을 비교하려고하는데, 같은 길이는 아니지만 순서는 같습니다. 내가하려는 것은 폴더에있는 모든 전체 파일의 목록을 가져 와서 각 파일을 MP4 또는 MTS로 이동하고 각각의 목록을 가지고 두 개의 정확한 위치를 비교하여 어떤 MTS 파일이 아닌지 확인합니다. MP4를 가지고 있다면, MTS 파일 이름을 새 목록에 추가하여 나중에 Finder에서 선택하십시오. 실제 세계에서 사용할 준비가 될 때까지 totalFiles 변수에 대한 자리 표시자를 사용하고 있습니다. 자리 표시 자에서 결과는 "6534-Seasons.MTS"여야합니다. MP4가 없기 때문입니다. 대신 MTS만큼 많지 않기 때문에 MP4 목록에서 멀리 검색 할 수 없기 때문에 충돌이 발생합니다. 이 상황에서 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 

고마워.

나는이 문제에 대한 접근 방식을 몇 번 개선했기 때문에 비교하는 것보다 더 좋은 방법이 있을까요?

답변

0

이렇게하면 원하는 것을 얻을 수 있습니다. 일부 지저분한 부분을 정리하고 불필요한 부분을 삭제했지만 MP4 목록을 문자열로 강제 변환하여 간단하게 "포함"할 수있었습니다. 나가 놓친 이것에서 더 많은 것을 당신이 필요로하는 경우에 저가 알게하십시오.

- .MP4가없는 파일을 찾아서 MTS 대응 파일을 찾으십시오.

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 

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") then 
      set end of MP4list to vidname as string 
     else 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 {MP4list, MTSlist} to siftfiles(totalFiles) 

-- turn the MP4 list into a string 
set otid to AppleScript's text item delimiters 
set AppleScript's text item delimiters to "|" 
set MP4string to "|" & (MP4list as string) & "|" 
set AppleScript's text item delimiters to otid 

--Compare the two lists 
set clickList to {} 
repeat with thename in MTSlist 
    set trimmedname to (text 1 thru -5 of thename) 
    if ("|" & trimmedname & ".") is not in MP4string then 
     set end of clickList to (trimmedname as string) 
    end if 
end repeat 

return clickList 
+0

dammit @jweaks 1 분 미만으로 나를 이길 수 있습니다! :-) – CRGreen

1

이것은 어떻습니까? 희망을 찾고 있습니다. 나는 코드를 수정하기보다는 내가하는 것처럼 일종의 일을했다. 희망은 그것이 ok 다. 필자는 올바른 확장자로 파일 이름을 먼저 빨아주는 "누구의 조항"을 사용하는 Finder의 기능을 활용합니다 (거대한 목록 인 경우, 잠시 시간이 걸릴 수 있음). 필자는 전체 Finder 참조 (또는 해당 별칭으로 AS 별칭)보다는 파일 이름 목록을 선호합니다. 그러면 필요한 경우 파일 경로 문자열을 다시 작성할 수 있습니다.

set ff to choose folder 
tell application "Finder" 
    set mpfours to name of files of ff whose name ends with ".mp4" 
    set mtses to name of files of ff whose name ends with ".mov" 
end tell 

--sorry, had to remove temp lines that were just for me 

set orphanMTSes to {} 

repeat with thisOne in mtses 
    set choppedMTS to (text 1 thru -4 of thisOne) --includes dot 
    if ((choppedMTS & "mp4") is not in mpfours) then set orphanMTSes to (orphanMTSes & thisOne) 
end repeat 
orphanMTSes 

[편집] 여기 고아의 목록을 복용하고 Finder에서 선택을하는 매우 효율적인 방법이다 (목록 그냥 파일 이름을하기 때문에, 나는 별칭 목록을 작성하고 사용할 수 있습니다)

set selectedList to {} 

repeat with f in orphanedMTSes 
    set selectedList to (selectedList & (alias ((ff as text) & f))) 
end repeat 

tell application "Finder" 
    select selectedList 
end tell