title: Delete files older than x days
body: <p>How can I find out when a file was created using java, as I wish to delete files older than a certain time period, currently I am deleting all files in a directory, but this is not ideal:</p>
  
  <pre><code>public void DeleteFiles() {
      File file = new File("D:/Documents/NetBeansProjects/printing~subversion/fileupload/web/resources/pdf/");
      System.out.println("Called deleteFiles");
      DeleteFiles(file);
      File file2 = new File("D:/Documents/NetBeansProjects/printing~subversion/fileupload/Uploaded/");
      DeleteFilesNonPdf(file2);
  }
  
  public void DeleteFiles(File file) {
      System.out.println("Now will search folders and delete files,");
      if (file.isDirectory()) {
          for (File f : file.listFiles()) {
              DeleteFiles(f);
          }
      } else {
          file.delete();
      }
  }
  </code></pre>
  
  <p>Above is my current code, I am trying now to add an if statement in that will only delete files older than say a week. </p>
  
  <p>EDIT:</p>
  
  <pre><code>@ViewScoped
  @ManagedBean
  public class Delete {
  
      public void DeleteFiles() {
          File file = new File("D:/Documents/NetBeansProjects/printing~subversion/fileupload/web/resources/pdf/");
          System.out.println("Called deleteFiles");
          DeleteFiles(file);
          File file2 = new File("D:/Documents/NetBeansProjects/printing~subversion/fileupload/Uploaded/");
          DeleteFilesNonPdf(file2);
      }
  
      public void DeleteFiles(File file) {
          System.out.println("Now will search folders and delete files,");
          if (file.isDirectory()) {
              System.out.println("Date Modified : " + file.lastModified());
              for (File f : file.listFiles()) {
                  DeleteFiles(f);
              }
          } else {
              file.delete();
          }
      }
  </code></pre>
  
  <p>Adding a loop now.</p>
  
  <p>EDIT</p>
  
  <p>I have noticed while testing the code above I get the last modified in :</p>
  
  <pre><code>INFO: Date Modified : 1361635382096
  </code></pre>
  
  <p>How should I code the if loop to say if it is older than 7 days delete it when it is in the above format?</p>