1 Replies - 425 Views - Last Post: 04 February 2013 - 12:03 PM Rate Topic: -----

#1 iburres  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 148
  • Joined: 05-September 12

EnumerateDirectory

Posted 04 February 2013 - 09:44 AM

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);
             }
         }
     }
	



Is This A Good Question/Topic? 0
  • +

Replies To: EnumerateDirectory

#2 iburres  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 148
  • Joined: 05-September 12

Re: EnumerateDirectory

Posted 04 February 2013 - 12:03 PM

Nevermind, I figured it out.


for (int i = 0; i < fileList.length; i++) {

  fileList[i].getAbsoluteFile(); 
  getSizeString(fileList[i].length()); 
  formattedDateString(fileList[i].lastModified());
  fileList[i].getName(); 
  gui.updateListing(fileList[i].getAbsolutePath(), getSizeString(fileList[i].length()),             fileList[i].getName(), formattedDateString(fileList[i].lastModified()));
enumerateDirectory(fileList[i]);
                
 }


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1