Process the largest file in a folder

Hi,
I have a basic applescript that sends the contents of a folder to iFlicks for video processing.

I would like to modify the script so that it only sends the largest file in the folder.

Any ideas?

Thanks.

Phil


on adding folder items to thisFolder after receiving addedItems
	
	repeat with movieFile in addedItems
		tell application "iFlicks"
			import movieFile without gui
		end tell
	end repeat
	
end adding folder items to


This would work…

on adding folder items to thisFolder after receiving addedItems
	
	tell application "Finder"
		-- get the information from this folder
		set {theSizes, theNames} to {size, name} of every file of thisFolder
		
		-- find the largest
		set largestFileName to missing value
		set largestSize to 0
		repeat with i from 1 to count of theSizes
			set thisSize to item i of theSizes
			if thisSize is greater than largestSize then
				set largestFileName to item i of theNames
				set largestSize to thisSize
			end if
		end repeat
		
		-- assemble the path to the largest file
		set largestFilePath to (thisFolder as text) & largestFileName
	end tell
	
	-- do something with the largest file
	tell application "iFlicks"
		import file largestFilePath without gui
	end tell
	
end adding folder items to

This works for finding the path to the largest file in a chosen folder:


set tLargest to 0
set tName to missing value
-- collect the files
tell application "Finder"
	set tSource to choose folder
	set tFiles to files of entire contents of tSource as alias list
end tell
-- "info for" is faster than the Finder for sizes
repeat with oneFile in tFiles
	set {size:tSize} to info for oneFile
	if tSize > tLargest then
		set tLargest to tSize
		set tName to contents of oneFile
	end if
end repeat

-- tName will contain an alias to the largest file in the chosen folder

Oops – Hank beat me to it and his script is more relevant to your problem