6 Replies Latest reply on Oct 10, 2013 11:55 PM by sporobolus

    Applescript - get  filenames AND creation dates from a folder + filter by creation date

    Oliver_Reid

      This Applescript gets the file names from a folder and inserts them into a field:

       

      (I am using the desktop folder as a test example)

       

      tell application "Finder"

      set oldDelimiters to AppleScript's text item delimiters

      set AppleScript's text item delimiters to return

      set gsourcefile to ""

      try

      set gsourcefile to every file in folder "/Thunderbolt/Users/oliver2/Desktop/" as text

      end try

      set AppleScript's text item delimiters to oldDelimiters

      end tell

      set cell "g_folder_items" to gsourcefile

       

       

      I'd like to

       

      1: get only file names from a folder where the creation date is less than N days old

       

      2: return the fileneme & tab & creation date for each file

       

      3: get file name alone -- the above returns the full path +filename (I can easliy fix this in filemaker but would like to know how to do this in Applescript)

       

       

      with respect to #1 I have tried

       

      try

      set gsourcefile to (every file in folder "Thunderbolt:Users:oliver2:Desktop:" whose creation date is greater than ((current date) - 100)) as text

      end try

       

      with no success

       

      Any suggestions would be appreciated

        • 1. Re: Applescript - get  filenames AND creation dates from a folder + filter by creation date
          seevogel

          current date

            --> 01.10.2013 18:31:41

           

          current date - 100

            --> 01.10.2013 18:30:01

           

           

           

          try this:

           

           

          set Mydate to current date

          set previousDay to Mydate - 68400

           

          tell application "Finder"

                    try

                              get every file in folder "Thunderbolt:Users:oliver2:Desktop:" whose creation date is greater than previousDay

                    end try

           

          end tell


          1 of 1 people found this helpful
          • 2. Re: Applescript - get  filenames AND creation dates from a folder + filter by creation date
            Oliver_Reid

            Tried that and get this output -- note th result is blank?

             

            tell current application

              current date

              --> date "Tuesday, October 1, 2013 12:50:57 PM"

            end tell

            tell application "Finder"

              get every file of folder "Thunderbolt:Users:oliver2:Desktop:" whose creation date > date "Thursday, September 19, 2013 11:04:17 PM"

              --> {document file "BSC CT Academy doc request.pdf" of folder "Desktop" of folder "oliver2" of folder "Users" of startup disk, document file "BSC Commitment Letter.pdf" of folder "Desktop" of folder "oliver2" of folder "Users" of startup disk, document file "IMG_0632.jpg" of folder "Desktop" of folder "oliver2" of folder "Users" of startup disk, document file "Import.log" of folder "Desktop" of folder "oliver2" of folder "Users" of startup disk, document file "Mickey%20Kydes%20Soccer%20-%20Camp%20Experience%20Survey%20(Responses).xlsx" of folder "Desktop" of folder "oliver2" of folder "Users" of startup disk, document file "OPES.fmp12" of folder "Desktop" of folder "oliver2" of folder "Users" of startup disk, document file "Untitled 11.pdf" of folder "Desktop" of folder "oliver2" of folder "Users" of startup disk, document file "fax_filing_service_request_form.pdf" of folder "Desktop" of folder "oliver2" of folder "Users" of startup disk, document file "panera.xlsx" of folder "Desktop" of folder "oliver2" of folder "Users" of startup disk, document file "roster.pdf" of folder "Desktop" of folder "oliver2" of folder "Users" of startup disk, document file "test.fmp12" of folder "Desktop" of folder "oliver2" of folder "Users" of startup disk}

            end tell

            Result:

            {""}

            • 3. Re: Applescript - get  filenames AND creation dates from a folder + filter by creation date
              erolst

              Try this:

               

              set folder_path to "Thunderbolt:Users:oliver2:Desktop:" as text

              set expiration_date to (current date) - (12 * days)

              try

                        tell application "Finder"

                                  set my_list to {get name of every file of folder folder_path whose creation date > expiration_date}

                        end tell

              end try

              • 4. Re: Applescript - get  filenames AND creation dates from a folder + filter by creation date
                sporobolus

                on 2013-10-01 9:15 Oliver_Reid wrote

                I'd like to

                 

                1:  get only file names from a folder where the creation date is less than  N  days old

                 

                2:  return the fileneme & tab  & creation date for each file

                 

                3: get file name alone  -- the above returns the full path +filename  (I can easliy fix this in filemaker but would like to know how to do this in Applescript)

                 

                this does what i think you are looking for:

                 

                set folder_path to path to desktop folder
                
                set the_files to my get_newer_files(folder_path, 50)
                set the_result to ""
                repeat with f in the_files
                   set {n, d} to {name, creation date} of f
                   set the_result to the_result & n & tab & my iso_date(d) & return
                end repeat
                set cell "g_folder_items" to the_result
                
                to get_newer_files(folder_path, day_count)
                   set the_result to ""
                   set after_date to (current date) - day_count * days
                
                   tell application "Finder"
                     if exists folder folder_path then
                       set the_result to files of folder folder_path whose creation date > 
                after_date
                     end if
                   end tell
                   return the_result
                end get_newer_files
                
                to iso_date(date_val)
                   -- cribbed from http://macscripter.net/viewtopic.php?id=24737
                   set {year:y, month:m, day:d} to date_val
                   tell (y * 10000 + m * 100 + d) as string to text 1 thru 4 & "-" & text 5 
                thru 6 & "-" & text 7 thru 8
                end iso_date
                

                 

                • 5. Re: Applescript - get  filenames AND creation dates from a folder + filter by creation date
                  Oliver_Reid

                  Thanks: That worked very well  -- (note, if copying from the posting, clear out spurious line breaks inserted on the web site or found in your email version)

                  • 6. Re: Applescript - get  filenames AND creation dates from a folder + filter by creation date
                    sporobolus

                    on 2013-10-09 9:50 Oliver_Reid wrote

                    Thanks: That worked very well  -- (note, if copying from the posting, clear out spurious line breaks inserted on the web site or found in your email version)

                     

                    you're welcome; glad you figured out the line breaks; i did send my email reply

                    with format=flowed, which works well if both ends support it, and i did use the

                    "code" tag to help the Jive (the forum software interpret) it, but

                    unfortunately Jive is notoriously bad at email