Interview Question

Release Engineer Interview El Dorado Hills, CA

How would you list all the files newer than yesterday?

Answer

Interview Answer

2 Answers

0

if files are all inside the arraylist/linked list called 'files' then:

while(files.hasNext())
{
file = files.next();

long fileDate = file.getDateofCreation();
long currentDate = system.getCurrentDate();

long diff = currentDate - fileDate;

long yesterday = currentDate - (24 * 60 * 60 * 1000); //yesterday in milliseconds hrs * min * secs

if ( diff > yesterday)
selectTheFile(file);
else
dicardTheFile(file);

}

George on Jul 29, 2011
0

If you are in the directory that has all the files you wanna sort, I believe there's a unix command to use:
find -maxdepth 1 -type f -mtime 1

Ina on Dec 7, 2012

Add Answers or Comments

To comment on this question, Sign In with Facebook or Sign Up