I have a script that does this. The problem is, it counts .DS_Store files in folders that have them (folders that have been opened), throwing off the count. How can I get the count to ignore .DS_Store files? Thanks in advance.
on open these_items
repeat with i from 1 to the count of these_items
set this_item to item i of these_items
set the item_info to info for this_item
process_item(this_item)
end repeat
end open
– this sub-routine processes folders
on process_item(this_item)
– NOTE that the variable this_item is a folder reference in alias format
tell application “Finder”
set the_folder to this_item
set num_folders to number of folders in entire contents of folder the_folder
set num_Items to number of files in entire contents of folder the_folder
display dialog “There are " & num_Items & " files, " & num_folders & " folders.”
set fileCount to 0
set folderCount to 0
tell application "Finder"
set theFileList to every item in folder theFolder
repeat with x in theFileList
if not character 1 of ((name of x) as string) is equal to "." then
if kind of x is equal to "Folder" then -- "folder" depends from the finder language
set folderCount to folderCount + 1
else
set fileCount to fileCount + 1
end if
end if
end repeat
end tell
display dialog "There are " & folderCount & " folders and " & fileCount & " files in this folder"
if your language in the finder is english this will work
set {numFiles, numAlias, numFolder, numInvis} to {0, 0, 0, 0}
set theFolder to (choose folder)
set folderContents to list folder theFolder
repeat with tmpItem in folderContents
set tmpInfo to info for file ((theFolder as string) & tmpItem)
if visible of tmpInfo is true then
if folder of tmpInfo is true then
set numFolder to (numFolder + 1)
else if alias of tmpInfo is true then
set numAlias to (numAlias + 1)
else
set numFiles to (numFiles + 1)
end if
else
set numInvis to (numInvis + 1)
end if
end repeat
display dialog (("Visible Files: " & numFiles & return & "Folders: " & numFolder & return & "Aliases: " & numAlias & return & "Invisibles: " & numInvis) as string)
These are all good . . . I see there is more than one way to skin this cat.
Here’s what I ended up using:
on open these_items
repeat with i from 1 to the count of these_items
set this_item to item i of these_items
set the item_info to info for this_item
process_item(this_item)
end repeat
end open
on process_item(this_item)
set fileCount to 0
set folderCount to 0
tell application “Finder”
set theFileList to every item in entire contents of folder this_item
repeat with x in theFileList
if not character 1 of ((name of x) as string) is equal to “.” then
if not character 1 of ((name of x) as string) is equal to “_” then
if kind of x is equal to “Folder” then
set folderCount to folderCount + 1
else
set fileCount to fileCount + 1
end if
end if
end if
end repeat
end tell
display dialog “There are " & folderCount & " folders, " & fileCount & " files in this folder”
Actually I have learned that this script, although it works fine on folders with small numbers of items, does not work on deeply nested folders with lots of items, such as iTunes folders.