title: How to Fetch a file name from a folder with current Date and Time using Java Code
body: <p>Am new to java automation and i have a scenario where i need to navigate to a particular folder, the folder has a list of files i need to filter by date and fetch a filename that got generated recently i.e. if the current time is 5:30pm i need to find the file name that got created between 5:28pm to current time (5:30pm)</p>
  
  <p>This has to be achieved using Java code, File names in the folder
  DOF_US_DELL_1.0_20160930_0516.CSV<br>
  DOF_US_DELL_1.0_20160930_0756.CSV<br>
  DOF_US_DELL_1.0_20161003_0346.CSV<br>
  DOF_US_DELL_1.0_20161003_0536.CSV<br>
  DOF_US_DELL_1.0_20161004_0747.CSV<br>
  DOF_US_DELL_1.0_20161005_0527.CSV</p>
  
  <p>Here is a piece of code that helps me to fetch the list of files in a directory</p>
  
  <pre><code>File dir = new File("C:\\FolderName");
                FilenameFilter filter = new FilenameFilter() {
                   public boolean accept
                   (File dir, String name) {
                      return name.startsWith("DOF");
                  }
                };
                String[] children = dir.list(filter);
                if (children == null) {
                   System.out.println("Either dir does not exist or is not a directory");
                } 
                else 
                {
                    System.out.println("# of the files in the folder is: "+children.length);
                    if(children.length&gt;0)
                    {
                      for (int i=0; i&lt;children.length; i++) 
                      {
                        String filename = children[i];
                        System.out.println(filename);
                      }
                    }
                    else
                    {
                        System.err.println("# of the files in the folder is: "+children.length);
                        fail("# of the files in the folder is: "+children.length);
                    }               
                } 
  </code></pre>
  
  <p>Thanks in Advance. </p>