Posted by
ctrueden on
Nov 07, 2008; 5:11pm
URL: http://imagej.273.s1.nabble.com/File-creation-date-in-a-macro-tp3694500p3694502.html
Hi Bill & Johannes,
You can, however, get the last modified date by calling File.lastModified(),
which might be good enough.
There is another option, depending on why you need such a date.
If what you want to know is the creation date of your dataset, you can use
Bio-Formats to query the creation date independent of file format. If there
is a creation date present in the metadata, Bio-Formats will use that --
otherwise it uses the file's last modified datestamp by default.
Below is a plugin that queries this value. You can't easily query
standardized metadata fields in a macro yet, but I could add this
functionality if there is interest.
-Curtis
-----------
//
// Creation_Date.java
//
import ij.IJ;
import ij.io.OpenDialog;
import ij.plugin.PlugIn;
import java.io.IOException;
import loci.formats.FormatException;
import loci.formats.IFormatReader;
import loci.formats.ImageReader;
import loci.formats.MetadataTools;
import loci.formats.meta.IMetadata;
public class Creation_Date implements PlugIn {
public void run(String arg) {
OpenDialog od = new OpenDialog("Open", null);
String dir = od.getDirectory();
String name = od.getFileName();
if (dir == null || name == null) return;
String id = dir + name;
IFormatReader r = new ImageReader();
IMetadata omexmlMeta = MetadataTools.createOMEXMLMetadata();
r.setMetadataStore(omexmlMeta);
try {
r.setId(id);
}
catch (FormatException exc) {
IJ.error(exc.getMessage());
}
catch (IOException exc) {
IJ.error(exc.getMessage());
}
String creationDate = omexmlMeta.getImageCreationDate(0);
IJ.showMessage("File is: " + id + "\nCreation date is: " +
creationDate);
}
}
On Fri, Nov 7, 2008 at 9:01 AM, Johannes Schindelin <
[hidden email]> wrote:
> Sorry, forgot to forward to the list...
>
> Okay, I misremembered. Java does not have the concept of a creation date.
> You'd have to call a program (on Linux, it would be "stat -c %z <file>"),
> and capture the output. Unfortunately, there does not seem to be a simple
> way to do this from ImageJ's macro language or JavaScript (yet).
>
> Sorry,
> Dscho
>