We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpIntegration › Getting system (Mac OS X) file information Date
Page Index Toggle Pages: 1
Getting system (Mac OS X) file information? Date? (Read 1416 times)
Getting system (Mac OS X) file information? Date?
Oct 19th, 2005, 8:07pm
 
There is a java application (also works for signed applets) function call that can be called on any file "lastModified()." It returns when that file was last modified by the system time stamp. It's a method of the File object.

Java API reference: http://java.sun.com/j2se/1.4.2/docs/api/java/io/File.html

I'm developing a Processing application that needs access to a file on the file system. I know where it is, and reading from the file (via Processing's function call "loadStrings()" ) works! So the file is there and the reading is fine. But how can I check to see if it's updated? when I call lastModified(), it works, but it returns 0 instead of some long int of the seconds.

Thanks for any help you can provide. I don't understand the differences between java and procesesing fully.

- - - - - - - - - - -
Zach Pousman - www.thinky.org
Re: Getting system (Mac OS X) file information? Da
Reply #1 - Oct 20th, 2005, 12:18am
 
there's a variable called "folder" which is a String that contains the path to the applet folder.

so for something inside that folder called "blah.txt", this should work:

File file = new File(folder, "blah.txt");

then you can use lastModified() on it just fine.

processing code is preprocessed into java, so most things just work.. the exception is generally anything using java.awt.* or java.swing.*, which should be avoided.
Re: Getting system (Mac OS X) file information? Da
Reply #2 - Nov 3rd, 2005, 3:59am
 
The above didn't work for me... It still returns 0. Maybe I don't understand lastModified() ? I take from the Java ref that it should return the number of second since the beginning of "unix time" (Jan 1, 1970).

Heres' the code snippet:

private boolean sensedStateChanged() {
   File datafile = new File(folder, "data.txt");
   println("file age: " + datafile.lastModified());
   if (datafile.lastModified() == dataAge) {
       dataAge = datafile.lastModified(); //save the time of last modify
       println("file age compared: " + dataAge);
       return true;
   }
   else { return false; }
 }


Any ideas?
Re: Getting system (Mac OS X) file information? Da
Reply #3 - Nov 3rd, 2005, 4:42pm
 
is the file in the sketch folder, or in the "data" subfolder of the sketch. it needs to be in just the sketch folder for it to work (unless you add data/ to its name).

also try a println(datafile.exists()) to see if you're actually getting the file.
Re: Getting system (Mac OS X) file information? Da
Reply #4 - Nov 4th, 2005, 3:27am
 
fry

"...the exception is generally anything using java.awt.* or java.swing.*, which should be avoided."

In Java mode, do you still advise against using awt/swing classes? For example, adding a simple button panel:

public class ButtonPanel extends PApplet {
 Panel buttons;
 Button bmove, bspin, bgrow;
 Point stageCenter;
 Dimension stage;

 void setup() {
   size(400, 300);
   setLayout(null);
   stage = new Dimension((width-width/4), height);
   stageCenter = new Point(stage.width/2, height/2);
   
   buttons = new Panel();
   buttons.setSize(width/4, height);
   buttons.setLocation(stage.width, 0);

   bmove = new Button("move");
   bspin = new Button("spin");
   bgrow = new Button("grow");

   bmove.setSize(width/4, 30);
   bspin.setSize(width/4, 30);
   bgrow.setSize(width/4, 30);

   buttons.add(bmove);
   buttons.add(bspin);
   buttons.add(bgrow);

   add(buttons);
 }
}


Re: Getting system (Mac OS X) file information? Da
Reply #5 - Nov 4th, 2005, 1:49pm
 
yep. results will be inconsistent across platforms, or different versions of java on the same platform.
Page Index Toggle Pages: 1