Re: How to list the creation times for a bunch of files?

Posted by Leon Espinosa-3 on
URL: http://imagej.273.s1.nabble.com/Parsing-a-log-file-to-extract-text-entries-of-File-Date-Modified-tp4552052p4646978.html

Dear Ethan, I have used "exec("GetFileInfo", "-d", path+file);" in mac os system (with developper tools installed). Maybe each OS has its own command to get the system time...

here is the code:

function getRealTime(file) {
        rawTime=exec("GetFileInfo", "-d", path+file);
        //print(rawTime);
        time=split(rawTime, " ");
        rawdate=split(time[0],"/");
        month=parseInt(rawdate[0]);
        day=parseInt(rawdate[1]);
        year=parseInt(rawdate[2]);
        rawHours=split(time[1],":");
        hours=parseInt(rawHours[0]);
        mins=parseInt(rawHours[1]);
        secs=parseInt(rawHours[2]);
        realTime=day*24*60*60+hours*60*60+mins*60+secs;
        return realTime;
}


Hope it helps...

Leon

Le 23 mars 2012 à 00:38, Cohen, Ethan D a écrit :

> OK, I got it to list the file creation time for a single file in ImageJ Macroscript...
>
> How to list the relative creation times for a bunch of files...to pipe to the TimeStamper?
>
> Is there a GetFileDates command?
>
>
> // OpenDialog Demo
> //
> // This macro demonstrates how do use the
> // File.openDialog() macro function.
>
>  path = File.openDialog("Select a File");
>  //open(path); // open the file
>  dir = File.getParent(path);
>  name = File.getName(path);
>  lastmod2 = File.lastModified(path);
>  print("LastMod", lastmod2);
>  print("Path:", path);
>  print("Name:", name);
>  print("Directory:", dir);
>  list = getFileList(dir);
>
>
>  print("Directory contains "+list.length+" files");
>
>  // Display info about the files
>  list = getFileList(dir);
>  for (i=0; i<list.length; i++)
>       print(list[i]+":  "+File.lastModified(list[i]));
>
> Ethan.
>
> -----Original Message-----
> From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Rasband, Wayne (NIH/NIMH) [E]
> Sent: Tuesday, March 06, 2012 4:22 PM
> To: [hidden email]
> Subject: Re: Parsing a log file to extract text entries of File Date Modified.
>
> On Mar 6, 2012, at 12:10 PM, Cohen, Ethan D wrote:
>
>> I have tried the FileDemo.txt macro to open a series of image files.
>>
>> You get output that looks like this in the ImageJ log file.
>>
>> image2.tif: 524456  Tue Mar 06 11:43:52 EST 2012
>>
>> 1.      What I want to do is parse this file for the file date modified info 11:43:52  and convert it from characters to numbers and then into seconds.
>>
>> 2.      How do I go about doing this? I am new to javascript/ ImageJ macros.
>>
>> 3.      Is there an existing macro/ImageJ function or script I should know about?  Time Stamp only gives fixed time intervals not real time intervals.
>>
>> 4.      Does File, Import Sequences, save the file Date Modified info of each file in a hidden stack I can access?
>
> Here is an example macro that opens a series of images and displays the modification date for each file:
>
>  dir = getDirectory("home")+"images"+File.separator;
>  run("Image Sequence...", "open=&dir sort");
>  for (i=1; i<=nSlices; i++) {
>     setSlice(i);
>     name = getMetadata("label");
>     date = File.dateLastModified(dir+name);
>     words = split(date, ": ");
>     hour = parseInt(words[3]);
>     min = parseInt(words[4]);
>     sec = parseInt(words[5]);
>     print(name, hour, min, sec);
>  }
>
> -wayne