Viewing 11 posts - 1 through 11 (of 11 total)
  • Counting items per day in a folder
  • seosamh77
    Free Member

    Weird request this one.

    I’ve got a folder on my mac desktop (can fire on to pc if this is easier)

    But I want to count the items in it by date.

    Ie

    1st april – 26 (files)

    2nd april – 15

    3rd april – 20

    on so on…

    Any ideas?

    joshvegas
    Free Member

    .bat file to create csv of all files and dates.

    Open it in excel. Count them.

    Is it a one off?

    In windoes you can right click on some white space in the folder and group by date.

    But that gets a bit vague over a week ago

    whitestone
    Free Member

    If you are on a Mac then use a script. A bit of searching comes up with this for ubuntu but there should be something similar for the Mac shell

    find . -type f -printf '%TY-%Tm-%Td\n' | sort | uniq -c

    -type f = files only
    
    
    whitestone
    Free Member

    The above command is recursive – I just ran it on my home folder and it took about 20 seconds to complete. If you only want to do the current folder and not subfolders then.

    find . -maxdepth 1 -type f -printf ‘%TY-%Tm-%Td\n’ | sort | uniq -c

    seosamh77
    Free Member

    find . -type f -print0 works, can’t get the sort and date stuff to work yet. Mac terminal obviously a bit different to linux.

    seosamh77
    Free Member

    Doesn’t understand ‘%TY-%Tm-%Td\n’

    scaled
    Free Member

    Try +%Y-%m-%d

    whitestone
    Free Member

    OK, Apple must use a different set of options to the find command. I can check when I get home to see what works. The %Ty etc is a format string to -printf. Is there anything in the man entry for find that mentions printf?

    Edit: there’s a copy of the Apple man page here https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man1/find.1.html

    What the line does is find all files in the current folder and for each one prints out its last modified date. That’s piped through sort and then through uniq, the -c flag tells uniq to prepend each line with the count.

    seosamh77
    Free Member

    ls -llt

    That gives me an output I can just fire into excel and make a pivot table (The desired result tbh.)

    Any way I can make that output comma separated? instead of spaces. So I can copy and paste into a text file and import into excel.

    whitestone
    Free Member

    If you want to split the output of ‘ls’ then you’ll need Sed or Awk. Here’s a short script using bash (I can’t remember if the Mac needs the #! line)

    #!/bin/bash
    ls -l | grep “^-” | awk ‘{
    key=$6$7
    freq[key]++
    }
    END {
    for (date in freq)
    printf “%s,%d\n”, date, freq[date]
    }’

    seosamh77
    Free Member

    sorted, I can save terminal output and there’s ways to import to excel with the spaces.

    Cheers for the help. 🙂

Viewing 11 posts - 1 through 11 (of 11 total)

The topic ‘Counting items per day in a folder’ is closed to new replies.