javascript - Find the file having lowest timestamp -


i have requirement needs done using java script , appreciate if can here.

  1. we have 10 files coming folder of format mmddyyyyhhmmss (ex. 07192013114030) - monthdayyearhourminutesecond
  2. the file gets dropped external system once every day
  3. when 11th file comes in need find file dropped on first , delete total count of files should 10 (latest 10 files)

sample example

07192013114030 07202013114030 07212013114030 07222013114030 07232013114030 07242013114030 07252013114030 07262013114030 07272013114030 07282013114030 

when 11th file comes in on 07292013114030, want find file 07192013114030 using java script.

i can provide incoming file names in format, ex. mm/dd/yyyy/hhmmss or mm_dd_yyyy_hh_mm_ss if helps using js

since can dates in format, them in yyyymmddhhmmss format. timestamps in array. there's not enough information system in question explain how loop through files pulling out timestamps , pushing them array.

basically should have array when you're done:

dates = ['20130719114030',          '20130720114030',          '20130721114030',          '20130722114030',          '20130723114030',          '20130724114030',          '20130725114030',          '20130726114030',          '20130727114030',          '20130728114030']; 

once done, sort array:

dates.sort(); 

dates in alphanumeric order, happens chronological order because of our date format. oldest date first 1 in array, so

dates[0] // '20130719114030' 

again, there's not enough information system explain how delete file, perhaps loop through files again find matching timestamp, delete file.


Comments