Calculate the time difference between two file names

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Guruganesh
    New Member
    • Mar 2010
    • 1

    Calculate the time difference between two file names

    i have to calculate the time diference of two file names namely

    File 1: CBE03KMD_2010_0 3_08_23_06_36.u pl
    File 2: CBE03KMD_2010_0 3_08_22_11_47.u pl


    see the date is same but the time is also mentioned in the file name. i need a function to calculate the time difference between the two file names.
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    Look up the C time functions.

    For each file name read each of the numbers from the name in individually and store in the relevent field of a struct tm.

    Use maketime to convert each struct tm to a time_t

    Use difftime to get the difference between the 2 times

    If you want use localtime to convert the timt_t back to a struct tm to get the difference as components.

    Comment

    • donbock
      Recognized Expert Top Contributor
      • Mar 2008
      • 2427

      #3
      You need to get the filenames into your program some how. Then you need to parse the names to extract the date fields. It is good practice to design the parser so that it recognizes and reports illegal filenames (where the date is unuseable). To get started on the parser you need to specify the precise format of the filenames.

      Comment

      Working...