how to react on files in a folder without a folder action

I created this script as a part of an applescript studio application to convert quicktime movies easily to flash files (using ffmpeg). Works great when dropping files on the app, but now I want to take matters to a higher level and want to detect if there are files stored in the input folder (items_in_folder)

I do not want to use a folder action! This is a script which is part of an ass application and because of that I do not want to use a folder action.

The idea is when someone starts the app the first thing it does is check the items_in_folder. If there are files in it it has to convert them and move them
to the output folder.

This is the script



on open theseItems
	
	-- read preferences from a stored text file
	set the_path to ((path to startup disk as text) & "Applications:FlashTMF:settings:")
	set the_file to (((the_path) as string) & "settings.txt") as file specification
	
	set read_data to read the_file as text
	
	-- set input/output folders
	set items_in_folder to (paragraph 1 of read_data) -- this is the folder in which the quicktime movies are stored
	set flash_out_folder to (paragraph 2 of read_data) -- in this file the encoded flash files are stored
	set items_out_folder to (paragraph 3 of read_data) -- after encoding the quicktime movies have to be moved to this folder
	
	
	repeat with thisItem in theseItems
		
		-- strip quicktime extension from the movie name
		set {name:thisName} to (info for thisItem without size)
		set x to the number of characters of thisName
		set the_new_name to characters 1 thru (x - 4) of thisName
		
		-- encode to flash
		do shell script "/opt/local/bin/ffmpeg -i " & the POSIX path of thisItem & " -acodec libmp3lame -ab 160 -f flv -s 1024x576 -ar 44100 -aspect 16:9 -pass 1 -b 2500 -r 25 -y " & flash_out_folder & the_new_name & ".flv"
		
		
		-- move file from in to out folder
		
		
		
		-- send message to user
		
	end repeat
	
	
end open



I googles my *ss of and also read a ton of posts on macscripter but can’t find the answer.

Anyone in for some help ??

thanks!

Hi Kemalski

maybe something as simple as “greater than 0” might do it

ie:

set items_in_folder to "Macintosh HD:Users:Budgie:Desktop:test:" as alias
tell application "Finder" to set theFiles to get every file of items_in_folder
if number of items in theFiles is greater than 0 then
	display dialog "Youve got files to process"
else
	display dialog "No files"
end if

I wrote this at one time to find all of the movie files inside of a folder. So the only thing I would add to what Budgie suggested is to make sure the found file is actually a movie file. You can do that like this…

property video_ext_list : {"3g2", "3gp", "3gp2", "3gpp", "3mm", "60d", "aep", "ajp", "amv", "asf", "asx", "avb", "avi", "avs", "bik", "bix", "box", "byu", "cvc", "dce", "dif", "dir", "divx", "dv", "dvr-ms", "dxr", "eye", "fcp", "flc", "fli", "flv", "flx", "gl", "grasp", "gvi", "gvp", "ifo", "imovieproject", "ivf", "ivs", "izz", "izzy", "lsf", "lsx", "m1v", "m2v", "m4e", "m4u", "m4v", "mjp", "mkv", "moov", "mov", "movie", "mp4", "mpe", "mpeg", "mpg", "mpv2", "msh", "mswmm", "mvb", "mvc", "nvc", "ogm", "omf", "prproj", "prx", "qt", "qtch", "rm", "rmvb", "rp", "rts", "sbk", "scm", "smil", "smv", "spl", "srt", "ssm", "svi", "swf", "swi", "tivo", "ts", "vdo", "vf", "vfw", "vid", "viewlet", "viv", "vivo", "vob", "vro", "wm", "wmd", "wmv", "wmx", "wvx", "yuv"} -- found here http://www.fileinfo.net/filetypes/video

set in_folder to (path to desktop folder as text) & "testFolder"

-- get all the files in the folder
tell application "Finder" to set all_files to every file of folder in_folder

if ((count of all_files) is greater than 0) then
	repeat with i from 1 to count of all_files
		if (isItAMovieFile(item i of all_files)) then -- make sure the file is a movie file before processing
			-- process item i of all_files
		end if
	end repeat
end if


(*============== SUBROUTINES ===============*)
on isItAMovieFile(this_movie)
	set this_movie to this_movie as Unicode text
	set item_info to info for file this_movie
	set is_alias to alias of (info for file this_movie)
	tell item_info
		set is_folder to folder
		set ne to name extension
		set its_kind to kind
		set file_type to file type
	end tell
	
	if is_folder is true or is_alias is true then
		return false
	else
		if ne is in video_ext_list then
			return true
		else if ne is missing value then
			if its_kind is "QuickTime Movie" then
				return true
			else if file_type is "Moov" then
				return true
			end if
		end if
	end if
	return false
end isItAMovieFile

thanks guys for both ideas!