App to gather detailed 'Get Info' for folder contents

Discussion in 'Mac Apps and Mac App Store' started by m021478, Oct 26, 2009.

  1. m021478 macrumors 6502

    Joined:
    Nov 23, 2007
    #1
    Does anyone know of an application that I can use to give me detailed information about a Finder Folder that I specify... specifically, I would like to point it at an "Images" folder I have and I'd like for the application to tell me the precise number of TIF, JPG, PSD, CR2, DNG, etc files that are contained within the folder I specify.

    Any suggestions would be greatly appreciated... Thanks!
     
  2. spinnerlys Guest

    spinnerlys

    Joined:
    Sep 7, 2008
    Location:
    forlod bygningen
    #2
  3. mysterytramp macrumors 65816

    mysterytramp

    Joined:
    Jul 17, 2008
    Location:
    Maryland
    #3
    A time like this, AppleScript might help. Here's a skeleton:

    Code:
    set theTarget to choose folder
    
    tell application "Finder"
    	set jpegs to count of (every item of folder (theTarget as string) whose name extension is "jpeg")
    	set jpgs to count of (every item of folder (theTarget as string) whose name extension is "jpg")
    	{jpegs, jpgs}
    end tell
    
    mt
     
  4. m021478 thread starter macrumors 6502

    Joined:
    Nov 23, 2007
    #4
    I was intrigued by this script and I tried running an expanded version of it, as shown below:

    Code:
    set theTarget to choose folder
    
    tell application "Finder"
    	set jpegs to count of (every item of folder (theTarget as string) whose name extension is "jpeg")
    	set jpgs to count of (every item of folder (theTarget as string) whose name extension is "jpg")
    	set tiff to count of (every item of folder (theTarget as string) whose name extension is "tiff")
    	set tif to count of (every item of folder (theTarget as string) whose name extension is "tif")
    	set psd to count of (every item of folder (theTarget as string) whose name extension is "psd")
    	set cr2 to count of (every item of folder (theTarget as string) whose name extension is "cr2")
    	set dng to count of (every item of folder (theTarget as string) whose name extension is "dng")
    	{jpegs, jpgs, tiff, tif, psd, cr2, dng}
    end tell
    ...but due to the fact that there doesn't seem to be any sort of progress indicator, I am not sure if it is even working? Will this script work if it is run on the root folder of a folder hierarchy in which all of the images are likely to be nested several levels deep inside of subfolders of the root folder? or will it only work when run on a root folder which contains images in the top level of the specified folder?

    I wasn't even able to return any results other than "{0, 0, 0, 0, 0, 0, 0}"??

    Any suggestions would be greatly appreciated... Thanks!
     
  5. spinnerlys Guest

    spinnerlys

    Joined:
    Sep 7, 2008
    Location:
    forlod bygningen
    #5

    I got it running by copying your script into clipboard, opening Apple Script, pasting it into, pressing the RUN button, choosing a folder (without subfolders, or maybe the contents of the subfolders won't be counted) and pressing okay. >>> {0, 2, 0, 0, 0, 163, 0}

    Choosing any parent folder resulted also in {0, 0, 0, 0, 0, 0, 0}


    Maybe one can even make a Finder Folder Action.
     
  6. m021478 thread starter macrumors 6502

    Joined:
    Nov 23, 2007
    #6
    What I am in need of is a way of running a script like this on a folder hierarchy of nested folders containing my images...

    Anyone feel like helpin' a brotha out??
     
  7. mysterytramp macrumors 65816

    mysterytramp

    Joined:
    Jul 17, 2008
    Location:
    Maryland
    #7
    This script does not walk through a folder tree collecting information. It only works on the folder theTarget.

    mt
     
  8. m021478 thread starter macrumors 6502

    Joined:
    Nov 23, 2007
    #8
    How can I get it to walk through a folder tree... or if a script like this can't do it, does anyone know of another one like it that can?

    Thanks!
     
  9. mysterytramp macrumors 65816

    mysterytramp

    Joined:
    Jul 17, 2008
    Location:
    Maryland
    #9
    Try this:

    Code:
    set theTarget to choose folder
    
    on folderCount(pathString)
    	tell application "Finder"
    		set jpegs to count of (every item of folder (theTarget as string) whose name extension is "jpeg")
    		set jpgs to count of (every item of folder (theTarget as string) whose name extension is "jpg")
    	end tell
    	return {jpegs, jpgs}
    end folderCount
    
    on processFolders(folderAliases)
    	set pFjpegs to 0
    	set pFjpgs to 0
    	repeat with fa in folderAliases
    		tell application "Finder"
    			set jpegs_temp to count of (every item of folder (fa as string) whose name extension is "jpeg")
    			set jpgs_temp to count of (every item of folder (fa as string) whose name extension is "jpg")
    			set folderList to folders of folder (fa as string)
    			set pFjpegs to pFjpegs + jpegs_temp
    			set pFjpgs to pFjpgs + jpgs_temp
    		end tell
    	end repeat
    	if folderList ≠ {} then
    		set moreCount to my processFolders(folderList)
    	else
    		set moreCount to {0, 0}
    	end if
    	return {(pFjpegs + (item 1 of moreCount)), (pFjpgs + (item 2 of moreCount))}
    end processFolders
    
    
    tell application "Finder"
    	set totals to {0, 0} -- initialize total var
    	set jpegs to count of (every item of folder (theTarget as string) whose name extension is "jpeg")
    	set jpgs to count of (every item of folder (theTarget as string) whose name extension is "jpg")
    	set totals to {jpegs, jpgs}
    	set folderList to folders of folder (theTarget as string)
    	if folderList ≠ {} then
    		set moreCount to my processFolders(folderList)
    		set item 1 of totals to (item 1 of totals) + (item 1 of moreCount)
    		set item 2 of totals to (item 2 of totals) + (item 2 of moreCount)
    	end if
    	totals
    	
    end tell
    
    EDIT: m021478: I'll try to find time tonight to update this with all the file types you use.

    mt
     
  10. brkirch macrumors regular

    Joined:
    Oct 18, 2001
    #10
    Try this command line utility:
    http://files.me.com/brkirch/ijt4f7

    The main purpose of this command line utility is HFS+ compression, but it can also be used to get detailed information about regular files and folders as well. For information on all file types in a folder, try:
    Code:
    afsctool -v -t ALL <folder>
    Or you can get information about specific types of files in a folder, like this:
    Code:
    $afsctool -v -t public.png -t public.jpeg ~/Desktop
    /Users/brkirch/Desktop:
    
    File content type: public.jpeg
    Number of HFS+ compressed files: 0
    Total number of files: 77
    File(s) size (uncompressed; reported size by Mac OS 10.6+ Finder): 26978268 bytes / 27.1 MB (megabytes) / 25.9 MiB (mebibytes)
    File(s) size (compressed - decmpfs xattr; reported size by Mac OS 10.0-10.5 Finder): 26978268 bytes / 27.1 MB (megabytes) / 25.9 MiB (mebibytes)
    File(s) size (compressed): 26978268 bytes / 27.1 MB (megabytes) / 25.9 MiB (mebibytes)
    Compression savings: 0.0%
    Approximate total file(s) size (files + file overhead): 27151000 bytes / 27.2 MB (megabytes) / 25.9 MiB (mebibytes)
    
    File content type: public.png
    Number of HFS+ compressed files: 0
    Total number of files: 18
    File(s) size (uncompressed; reported size by Mac OS 10.6+ Finder): 15076481 bytes / 15.1 MB (megabytes) / 14.4 MiB (mebibytes)
    File(s) size (compressed - decmpfs xattr; reported size by Mac OS 10.0-10.5 Finder): 15076481 bytes / 15.1 MB (megabytes) / 14.4 MiB (mebibytes)
    File(s) size (compressed): 15076481 bytes / 15.1 MB (megabytes) / 14.4 MiB (mebibytes)
    Compression savings: 0.0%
    Approximate total file(s) size (files + file overhead): 15122800 bytes / 15.1 MB (megabytes) / 14.4 MiB (mebibytes)
    
    Totals of file content types
    Number of HFS+ compressed files: 0
    Total number of files: 95
    File(s) size (uncompressed; reported size by Mac OS 10.6+ Finder): 42054749 bytes / 42.3 MB (megabytes) / 40.3 MiB (mebibytes)
    File(s) size (compressed - decmpfs xattr; reported size by Mac OS 10.0-10.5 Finder): 42054749 bytes / 42.3 MB (megabytes) / 40.3 MiB (mebibytes)
    File(s) size (compressed): 42054749 bytes / 42.3 MB (megabytes) / 40.3 MiB (mebibytes)
    Compression savings: 0.0%
    Approximate total file(s) size (files + file overhead): 42273800 bytes / 42.3 MB (megabytes) / 40.3 MiB (mebibytes)
    
    Folder contains no compressed files
    Total number of files: 217
    Total number of folders: 9
    Total number of items (number of files + number of folders): 226
    Folder size (uncompressed; reported size by Mac OS 10.6+ Finder): 1211441716 bytes / 1.21 GB (gigabytes) / 1.13 GiB (gibibytes)
    Folder size (compressed - decmpfs xattr; reported size by Mac OS 10.0-10.5 Finder): 1211441716 bytes / 1.21 GB (gigabytes) / 1.13 GiB (gibibytes)
    Folder size (compressed): 1211441716 bytes / 1.21 GB (gigabytes) / 1.13 GiB (gibibytes)
    Compression savings: 0.0%
    Approximate total folder size (files + file overhead + folder overhead): 1212074012 bytes / 1.21 GB (gigabytes) / 1.13 GiB (gibibytes)
    This program currently uses UTIs to determine file types, here is a list:
    http://developer.apple.com/mac/libr...ptual/understanding_utis/utilist/UTIlist.html

    Edit: I've added support for file extensions as well so now
    Code:
    $afsctool -v -t png -t jpg ~/Desktop
    should work almost the same as
    Code:
    $afsctool -v -t public.png -t public.jpeg ~/Desktop
    There are still advantages to using a UTI instead of a file extension, for example a UTI will match files with different extensions that are the same type of file.
     
  11. m021478 thread starter macrumors 6502

    Joined:
    Nov 23, 2007
    #11
    Can you please give me a brief breakdown of how to use the afsctool command line utility you provided?

    • How do I install it?
    • How do I run it?
    • How do I use it to get information about specific types of files in a folder as you've mentioned in the second portion of your previous response?
    Thanks!
     
  12. brkirch macrumors regular

    Joined:
    Oct 18, 2001
    #12
    It needs to be installed to the /usr/local/bin/ directory. If you are unsure how to do that, just use this installer.

    Open Applications > Utilities > Terminal. Then you can type 'afsctool' and return into the terminal window to get usage information for afsctool. You could for example try typing
    Code:
    afsctool -v /System
    and then return to get information on your system folder.

    If you want information on TIF, JPG, PSD, CR2, and DNG files in a folder, type
    Code:
    afsctool -v -t TIF -t JPG -t PSD -t CR2 -t DNG
    and then type space and drag and drop the folder onto the terminal window and type return.
    You should get some output that has statistics sorted by the file content types and file extensions. This information includes how many of each type of file exists in the folder, and how much disk space is used up by files of that type.
     
  13. mysterytramp macrumors 65816

    mysterytramp

    Joined:
    Jul 17, 2008
    Location:
    Maryland
    #13
    Better script ...

    Just give it a list of file extensions you want to search for in the dialog box. It searches for each.

    If you search for the same file types each time, the dialog box might be a bit tedious, but it can easily be replaced by commenting out the "display dialog" command and replacing it with something like:

    set dialogString to "jpg, png, ..." etc.

    Let me know how this performs. I did this the "easy" way to get it done sooner. I believe there's a much faster way, but it would take quite a bit of testing.

    Code:
    global extnCheck
    
    on folderCount(pathString)
    	tell application "Finder"
    		set extnCount to count of (every item of folder (theTarget as string) whose name extension is extnCheck)
    	end tell
    	return extnCount
    end folderCount
    
    on processFolders(folderAliases)
    	set pFextnCount to 0
    	repeat with fa in folderAliases
    		tell application "Finder"
    			set extn_temp to count of (every item of folder (fa as string) whose name extension is extnCheck)
    			set folderList to folders of folder (fa as string)
    			set pFextnCount to pFextnCount + extn_temp
    		end tell
    	end repeat
    	if folderList ≠ {} then
    		set moreCount to my processFolders(folderList)
    	else
    		set moreCount to 0
    	end if
    	return pFextnCount + moreCount
    end processFolders
    
    -- Initialize variables
    
    set listOfExtns to {}
    set countOfExtns to {}
    set TID to AppleScript's text item delimiters
    set whichExtn to 1
    
    set theTarget to choose folder with prompt "Select folder of files:"
    
    display dialog "Please provide list of file extensions" & return & "(separated by commas, exclude periods):" default answer "txt, jpg" buttons {"Cancel", "OK"} default button 2
    
    set dialogString to text returned of result
    
    set AppleScript's text item delimiters to {", ", ","}
    
    set listOfExtns to text items of dialogString
    
    set AppleScript's text item delimiters to TID
    
    repeat with x from 1 to count of listOfExtns
    	set countOfExtns to countOfExtns & {0}
    end repeat
    
    repeat with ext in listOfExtns
    	
    	set totals to 0
    	
    	tell application "Finder"
    		set extSum to count of (every item of folder (theTarget as string) whose name extension is ext)
    		set totals to extSum
    		set folderList to folders of folder (theTarget as string)
    		if folderList ≠ {} then
    			set extnCheck to ext
    			set moreCount to my processFolders(folderList)
    		end if
    	end tell
    	set item whichExtn of countOfExtns to extSum + moreCount
    	set whichExtn to whichExtn + 1
    end repeat
    
    set whichExtn to 1
    repeat with x from 1 to (count of listOfExtns)
    	set extStr to item x of listOfExtns
    	set countStr to item x of countOfExtns
    	
    	display dialog "The count of files with " & extStr & " as extension is " & countStr
    end repeat
    mt
     
  14. m021478 thread starter macrumors 6502

    Joined:
    Nov 23, 2007
    #14
    I don't believe the script is working...

    I ran it on a folder entitled "2006", which contains every RAW image I shot in that year, all of which are in the Adobe Digital Negative format (DNG). The script reports that there are 693 files with DNG as the extension, when a simple spotlight search shows that there are more than 10,000 (and I know for a fact that there are more than 10,000)...

    Any ideas? Thanks!
     
  15. mysterytramp macrumors 65816

    mysterytramp

    Joined:
    Jul 17, 2008
    Location:
    Maryland
    #15
    This really bothers me.

    I expected you to say how slow the script was, not that the math was bad.

    Could there be a wrinkle is your directory tree that the script doesn't expect? Maybe aliases of folders, or aliases of files? (doubtful ...)

    There's a bug that 10.6.2 is supposed to fix involving Apple Events, which would mean that if you restart and run the script again, you'd get a different number ... but the script should have thrown an error before you get to 693.

    Let me think about it.

    mt
     
  16. MacUser2525 macrumors 68000

    MacUser2525

    Joined:
    Mar 17, 2007
    Location:
    Canada
    #16

    ls -R /path/to/2006/ |grep .DNG |wc -l

    Would get the number of files with the .DNG extension in all directories under the 2006 you could modify the command for the other files and if not wanting to repeatedly type in the commands all the time then you could make a script like this to get your other files.

    Code:
    #!/bin/bash
    
    echo "DNG TotaL"
    ls -R /path/to/2006/ |grep .DNG |wc -l
    
    echo "jpg Total"
    ls -R /path/to/2006/ |grep .jpg |wc -l
    
    Once you have all the lines in there you want with the proper paths and extensions to be searched for each type then use the chmod +x /path/to/script_file.sh to make it executable then /path/to/script_file.sh to get your totals.
     
  17. brkirch macrumors regular

    Joined:
    Oct 18, 2001
    #17
    Actually that will not work correctly, as ls might put some file names on the same line, it doesn't guarantee that file names end with ".DNG", and folder names that contain ".DNG" will also be counted. Using find would work a lot better:
    Code:
    find /path/to/2006/ -iname "*.DNG" -type f | wc -l
    I guess I could throw together a quick applescript for this:
    Code:
    property file_extensions_list : {"tif", "jpg", "psd", "cr2", "dng"}
    
    set selected_extensions to false
    repeat until selected_extensions ≠ false
    	set selected_extensions to choose from list file_extensions_list with prompt "Select file extensions to get file count for:" cancel button name "Add Extension" with multiple selections allowed
    	if selected_extensions = false then
    		try
    			set new_extension to text returned of (display dialog "Enter File Extension to Add:" default answer "" buttons {"Cancel", "Add"} cancel button 1 default button 2)
    			if new_extension is not "" then set file_extensions_list to file_extensions_list & new_extension
    		end try
    	end if
    end repeat
    set selected_folder to choose folder
    set folder_info to ""
    repeat with current_extension in selected_extensions
    	set file_count to (do shell script "find " & quoted form of POSIX path of selected_folder & " -iname " & quoted form of ("*." & current_extension) & " -type f | wc -l") as integer
    	if folder_info ≠ "" then set folder_info to folder_info & return
    	set folder_info to folder_info & "Number of " & current_extension & " files: " & file_count
    end repeat
    display dialog folder_info
     
  18. MacUser2525 macrumors 68000

    MacUser2525

    Joined:
    Mar 17, 2007
    Location:
    Canada
    #18
    No doubt it was a quick one liner not really tested much, the find is faster when I do it on the directory of ~16000 items I tried the ls on as well.
     
  19. m021478 thread starter macrumors 6502

    Joined:
    Nov 23, 2007
    #19
    Script works perfectly! Thanks for your help!
     
  20. balamw Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #20
    I know you've already got a solution, but here's a more "unix-y" way to do it that only requires one find (so it probably scales better) and does not require any knowledge of the file extensions in the folder hierarchy:

    Code:
    find . -type f | sed -e 's/.*\.//' | sort | uniq -c | sort -rn
    You can customize the filter between the find and first sort to better suit your needs. I borrowed the sed version from here: http://www.unix.com/shell-programming-scripting/60471-recursicely-search-rename-file-extension.html

    I've used variations on the sort|uniq|sort for lots of stuff over the years, so it's a useful tool to know.

    B
     

Share This Page