客戶端有一個大型的WordPress上傳文件夾,每個文件有7或8個大小版本。尋找符合規則的文件名與Applescript
我正在尋找篩選出所有具有-NNNxNNN
作爲文件名稱的一部分的圖像 - 「NNN」是任何數字。對於如:
- 最初上傳的文件:
7Metropolis711.jpg
- 實例大小相同文件的版本:
7Metropolis711-792x373.jpg
我使用的Automator這一點,並且我只是在尋找的AppleScript過濾出從文件夾輸入IE ..這些文件:
客戶端有一個大型的WordPress上傳文件夾,每個文件有7或8個大小版本。尋找符合規則的文件名與Applescript
我正在尋找篩選出所有具有-NNNxNNN
作爲文件名稱的一部分的圖像 - 「NNN」是任何數字。對於如:
7Metropolis711.jpg
7Metropolis711-792x373.jpg
我使用的Automator這一點,並且我只是在尋找的AppleScript過濾出從文件夾輸入IE ..這些文件:
這裏是另一種方法:
on run {input}
set newList to {}
repeat with aFile in input
tell application "System Events" to set fileName to name of aFile
try
set variableName to do shell script "echo " & quoted form of fileName & " | grep -Eo [0-9]{3}x[0-9]{3}"
on error
set end of newList to (aFile's contents)
end try
end repeat
return newList
end run
試試這個。你可以看到一個處理程序「isFormatNNNNNNN(fileName)」,它測試你的格式的文件名。顯然刪除代碼的前兩行。他們被使用,所以我可以在AppleScript編輯器中進行測試。它們應該等於Automator中的輸入變量。
編輯:根據您的意見,我修改劇本要佔一多「 - 」的文件名。現在我開始查看文件擴展名前面的文本,因爲我假設您的格式是文件名中的最後一個字符。
它在Automator中不起作用,因爲您必須在代碼周圍放置「on run {input,parameters}」。我現在已經完成了,只需將其複製/粘貼到automator即可。
on run {input, parameters}
set newList to {}
repeat with aFile in input
if not (my isFormatNNNxNNN(aFile)) then set end of newList to (contents of aFile)
end repeat
return newList
end run
on isFormatNNNxNNN(theFile)
set theBool to false
try
tell application "System Events"
set fileName to name of theFile
set fileExt to name extension of theFile
end tell
set endIndex to (count of fileExt) + 2
set nameText to text -(endIndex + 7) thru -endIndex of fileName
if nameText starts with "-" then
if character 5 of nameText is "x" then
-- test for numbers
text 2 thru 4 of nameText as number
text 6 thru 8 of nameText as number
set theBool to true
end if
end if
end try
return theBool
end isFormatNNNxNNN
你說你希望每個組在同一時間對工作流的單次運行排序尺寸。或在工作流程的單次運行中設置單個尺寸 – markhunte
我只想要原件。所以假設任何帶有「-NNNxNNN」的圖像都是一個調整大小的圖像,可以跳過。 – Mark