Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

EnumerateDirectory

$
0
0
This following code displays the directory path perfectly fine in a GUI, four times that is. I want to display the size, type, and date last modified after the base path as well. I tried using a vector, but that didn't work. I believe I am missing something from the enumerateDirectory method, but all my attempts have failed.

public void showDirectoryContents(String basePath)
	{
		
		try {
			File show = new File(basePath);
			
			if(show.exists() && show.isDirectory()) {
				
				enumerateDirectory(show);
				
			}
			else if (!show.exists()){
				
				throw new Exception();
			}

		}
		catch (Exception e) {
			
			e.printStackTrace();
			
			if (basePath == null) {
				
				JOptionPane.showMessageDialog(null, "No directory chosen", "Error",
						JOptionPane.ERROR_MESSAGE);
			}
			
			else
	        {
	            JOptionPane.showMessageDialog(null, "Exception - " + basePath + 
	            		" is not a valid file or directory!", "Error", JOptionPane.ERROR_MESSAGE);
	        }

		}
	}
	
	/**
	 *	Recursive method to enumerate the contents of a directory.
	 *
	 *	@param	f	directory to enumerate
	 */

private void enumerateDirectory(File f)
	{
		
    	
    	if (f.isDirectory())
	    {
	        
    		 try {
                 File[] fileList = f.listFiles();
                
				for (int i = 0; i < fileList.length; i++) {
                    
                     enumerateDirectory(fileList[i]);

                 }
                 
                 gui.updateListing(basePath, basePath, basePath, basePath);
             }
             catch (Exception e) {
                 System.out.println(e);
             }
         }
     }
	


Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>