JAVA – Search File In Folder

class SearchFileInFolder 
{   
    public void SearchPath(File folder) throws IOException
    {

		File[] listOfFiles = folder.listFiles();
					 
		if (listOfFiles.length < 1)
		{
			System.out.println("\n #---This Folder Empty: "+folder.getAbsolutePath());
		}
		
		else
		{
			System.out.println("\n #---List of Files & Folder: "+folder.getAbsolutePath());
			for (File file : listOfFiles) 
			{
			   if(file.isDirectory())
			   {
					System.out.println("FOLDER: "+file.getAbsolutePath());
					SearchPath(file.getAbsoluteFile());
			   }
			   
			   if(file.isFile())
			   {
					System.out.println("FILE: "+file.getAbsolutePath());
			   }
			}
		}  
    }
    
	public static void main(String[] args) throws IOException 
	{
		SearchFileInFolder obj = new  SearchFileInFolder();
		//File foldrs = new File("C:\Users");
		File foldrs = new File("### PATH ###");
		for (File files : foldrs.listFiles())
		{
			if(files.isDirectory())
				obj.SearchPath(files);                 
		}   
	}
}

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.