N
News-proxy.phk.philips.com
I want write a program delete old files. Need to change the modified date .
How to Calculate Date diff ?
ldatediff = Now - (long) files.lastModified() ?
import java.io.*;
import java.util.*;
//import java.util.Date;
import java.text.*;
public class Dir_t {
static int indentLevel = - 1;
TimeZone zone = new SimpleTimeZone(8*60*60*1000,"GMT+0800");
Calendar cal = Calendar.getInstance(zone);// this seems to be a point
Date currdate = new Date();
Dir_t (String path) {
listPath (new File (path));
}
void listPath (File path) {
File files []; //List of files in a Directory
indentLevel++; // Going Down...
String datestr;
int k;
long ldatediff ;
// Create list of files in this dir
files = path.listFiles();
// Sort with help of Collections API
Arrays.sort(files);
for (int i= 0, n=files.length ; i < n ; i++) {
for (int indent = 0 ; indent < indentLevel; indent++) {
System.out.print(" ");
}
cal.set(Calendar.YEAR, 1970); // example
DateFormat formatter = new SimpleDateFormat();
formatter.setCalendar(cal); //this is necessary
Date date = new Date(files.lastModified());
formatter.format(date);
cal.add(cal.DATE,0); /* Date Offset */
datestr = cal.get(cal.YEAR) +"/";
k = cal.get(cal.MONTH) + 1;
if ( k <= 9 )
datestr = datestr + "0" + k + "/";
else
datestr = datestr + k + "/";
if (cal.get(cal.DATE) < 10 )
datestr = datestr + "0" + cal.get(cal.DATE);
else
datestr = datestr + cal.get(cal.DATE);
// Calculate Date diff
ldatediff = (long) files.lastModified() ;
// System.out.println(files.toString() + ", "
// + (new Date (files.lastModified())) );
System.out.println( datestr + " " + ldatediff + " " +
files.toString()) ;
if (files.isDirectory()) {
listPath(files);
}
}
indentLevel--; // and going up
}
public static void main (String args[]) {
new Dir_t(args[0]);
}
}
How to Calculate Date diff ?
ldatediff = Now - (long) files.lastModified() ?
import java.io.*;
import java.util.*;
//import java.util.Date;
import java.text.*;
public class Dir_t {
static int indentLevel = - 1;
TimeZone zone = new SimpleTimeZone(8*60*60*1000,"GMT+0800");
Calendar cal = Calendar.getInstance(zone);// this seems to be a point
Date currdate = new Date();
Dir_t (String path) {
listPath (new File (path));
}
void listPath (File path) {
File files []; //List of files in a Directory
indentLevel++; // Going Down...
String datestr;
int k;
long ldatediff ;
// Create list of files in this dir
files = path.listFiles();
// Sort with help of Collections API
Arrays.sort(files);
for (int i= 0, n=files.length ; i < n ; i++) {
for (int indent = 0 ; indent < indentLevel; indent++) {
System.out.print(" ");
}
cal.set(Calendar.YEAR, 1970); // example
DateFormat formatter = new SimpleDateFormat();
formatter.setCalendar(cal); //this is necessary
Date date = new Date(files.lastModified());
formatter.format(date);
cal.add(cal.DATE,0); /* Date Offset */
datestr = cal.get(cal.YEAR) +"/";
k = cal.get(cal.MONTH) + 1;
if ( k <= 9 )
datestr = datestr + "0" + k + "/";
else
datestr = datestr + k + "/";
if (cal.get(cal.DATE) < 10 )
datestr = datestr + "0" + cal.get(cal.DATE);
else
datestr = datestr + cal.get(cal.DATE);
// Calculate Date diff
ldatediff = (long) files.lastModified() ;
// System.out.println(files.toString() + ", "
// + (new Date (files.lastModified())) );
System.out.println( datestr + " " + ldatediff + " " +
files.toString()) ;
if (files.isDirectory()) {
listPath(files);
}
}
indentLevel--; // and going up
}
public static void main (String args[]) {
new Dir_t(args[0]);
}
}