java program scan folder find files using time

Solutions on MaxInterview for java program scan folder find files using time by the best coders in the world

showing results for - "java program scan folder find files using time"
Ahmed
28 Sep 2019
1import java.io.*;
2import java.util.*;
3import java.awt.Desktop;
4public class Filesearch2 {
5
6
7    public static void main(String[] args)throws IOException {        
8        Filesearch2 fs = new Filesearch2();
9        Scanner scan = new Scanner(System.in);
10        System.out.println("Enter the file to be searched.. " );
11        String name = scan.next();
12        System.out.println("Enter the directory where to search ");
13        String directory = scan.next();
14        fs.findFile(name,new File(directory));
15    }
16    public void findFile(String name,File file1)throws IOException
17    {      
18        File[] list = file1.listFiles();       
19        if(list!=null)  
20     {                          
21        for(File file2 : list)
22        {            
23            if (file2.isDirectory())
24            {
25                findFile(name,file2);             
26            }
27            else if (name.equalsIgnoreCase(file2.getName()))
28            {                                                              
29                System.out.println("Found");                
30                System.out.println("File found at : "+file2.getParentFile());
31                System.out.println("Path diectory: "+file2.getAbsolutePath());
32                String p1 = ""+file2.getParentFile();
33                File f2 = new File(p1);
34                Desktop.getDesktop().open(f2);                               
35            }                      
36        }        
37      }
38    }        
39}
40