Quantcast

Parsing a log file to extract text entries of File Date Modified.

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Parsing a log file to extract text entries of File Date Modified.

Cohen, Ethan D
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?

Thanks,

Ethan,


Ethan Cohen, Ph.D.
FDA Center for Devices and Radiological Health
Office: Rm 1204 WO62
White Oak Federal Res Ctr.
10903 New Hampshire Ave.
Silver Spring, MD 20993
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Parsing a log file to extract text entries of File Date Modified.

Rasband, Wayne (NIH/NIMH) [E]
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Parsing a log file to extract text entries of File Date Modified.

Cohen, Ethan D
Wayne:

1. OK, on ImageJ (Fiji) in WinXP, when I execute your imageJ macroscript file it does not work, and no file open is requested.

2. If I open an image series stack, and then run the script it works, I get the filenames, but all the file modified times are just zeros.

3. If I run the following ImageJ macroscript, I can open a file, but then all the times are zero from 1969...  Sound familiar?




// 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);
  print( File.dateLastModified(name));
  print (File.lastModified(name));
  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.dateLastModified(dir+list[i]));

THE IMAGEJ LOG...I will spare you the redundencies...

Wed Dec 31 19:00:00 EST 1969
0
Path: C:\Documents and Settings\edc\Desktop\OCT\100819\Run1-37uA\OCT_153014.bmp
Name: OCT_153014.bmp
Directory: C:\Documents and Settings\edc\Desktop\OCT\100819\Run1-37uA
Directory contains 85 files
0071-0145-0368.roi:  Wed Dec 31 19:00:00 EST 1969
image153000.bmp:  Wed Dec 31 19:00:00 EST 1969
image160022.bmp:  Wed Dec 31 19:00:00 EST 1969
M1-37uA.avi:  Wed Dec 31 19:00:00 EST 1969

PC specific java date problem?

I can get the times (in seconds) in a little Python script though. Like:
import os
filename = "C:/Documents and Settings/edc/Desktop/OCT/100819/Run1-37uA/"
statbuf = os.stat(filename)
print "Modification time:",statbuf.st_mtime

Started MacroTime.py at Wed Mar 21 18:16:35 EDT 2012
Modification time: 1332360656


4. Oddly in your FileDemo.txt it works, but you have to create the file.

There seems to be a discussion from 2008 about this issue here:
http://imagej.1557.n6.nabble.com/File-creation-date-in-a-macro-td3694500.html


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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

Cohen, Ethan D
In reply to this post by Rasband, Wayne (NIH/NIMH) [E]
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

Leon Espinosa-3
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

Cohen, Ethan D
Leon:

Unfortunately, I am running a Windows XP box, so while there is "exec" in ImageJ Macro script,  I am not sure how to pass the user selected directory to it.

There are a bunch of "exec" examples for Wintel, but no wildcards, or user input.

Ethan.

-----Original Message-----
From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Leon Espinosa
Sent: Thursday, March 22, 2012 8:17 PM
To: [hidden email]
Subject: Re: How to list the creation times for a bunch of files?

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
Loading...