Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Counts Folders & Files' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Counts Folders & Files
Authored by: cfoster on Nov 09, '04 12:18:27PM

Here's a slightly optimized version that counts apps, files and folders:

-- To treat Appliccation bundles as Applications, use the first FOLDER_TYPE.
-- To treat them as folders (and parse their contents), use the second.

property FOLDER_TYPES : "Folder Volume"
--property FOLDER_TYPES : "Application Folder Volume"

global anzahlApps
global anzahlFiles
global anzahlFolders

on run
	set theFileList to (choose folder) as list -- Select a folder
	open theFileList -- then just treat it like a drag & drop
end run

on open theFileList
	
	set anzahlApps to 0
	set anzahlFiles to 0
	set anzahlFolders to 0
	
	repeat with one_item in theFileList
		File_or_Folder(one_item)
	end repeat
	
	activate me
	display dialog "CountEverest says:" & return & ¬
		"   Total Apps:    " & anzahlApps & return & ¬
		"   Total Files:     " & anzahlFiles & return & ¬
		"   Total Folders: " & anzahlFolders ¬
		buttons {"OK"} default button {"OK"} giving up after 20
	
end open


on File_or_Folder(one_item)
	
	tell application "Finder" to set item_kind to the kind of one_item
	
	if (FOLDER_TYPES contains item_kind) then -- is it some kind of folder?
		
		tell application "Finder" to set folder_contents to every item of one_item -- does it have contents?
		if (item_kind is "Application" and folder_contents is equal to {}) then
			set anzahlApps to anzahlApps + 1 -- It's a non-bundle Application
		else
			set anzahlFolders to anzahlFolders + 1 -- It's a Volume, Folder, or Application bundle
		end if
		
		repeat with one_item in folder_contents
			my File_or_Folder(one_item as alias)
		end repeat
		
	else if (item_kind is equal to "Application") then -- only execute when Apps are not folders.
		set anzahlApps to anzahlApps + 1
	else
		set anzahlFiles to anzahlFiles + 1 -- everything else is considered a document.
	end if
	
end File_or_Folder

Note: Applications Bundles are counted as folders



[ Reply to This | # ]
Counts Folders & Files
Authored by: cfoster on Nov 09, '04 12:25:50PM

Whoops. That last note about application bundles is wrong. They are treated as just apps with the current property selection.



[ Reply to This | # ]