Results 1 to 9 of 9
  1. #1
    ralph is offline Member
    Join Date
    Nov 2012
    Posts
    36
    Rep Power
    0

    Default More efficient way to find the path of all folders with a specific name

    This is a GUI. When a button is clicked, this code runs and puts all the paths inside a drop down box.

    However, it takes about 15 seconds to run which is obviously not good when a user is playing around with a GUI.

    Java Code:
    static void Process(File aFile)
        {
    
    	    if (aFile.isDirectory())
    	    {
    	    	if (aFile.getPath().toString().endsWith("wwwroot") || aFile.getPath().toString().endsWith("cfusion.war"))
    	    	{
    	    		cbCFServerPath.add(aFile.getPath());
    		    }
    	    	
    	    	 File[] listOfFiles = aFile.listFiles();
    	    	 if(listOfFiles!=null)
    	    	 {
    	   	        for (int i = 0; i < listOfFiles.length; i++)
    	   	          Process(listOfFiles[i]);
    	   	     } 
    	    }
    	  }
    Java Code:
     buttonScan.addSelectionListener( new SelectionAdapter()
            {
                public void widgetSelected( SelectionEvent e )
                {
                	String nam = "C:/";
            	    File aFile = new File(nam);
            	    Process(aFile);
            	    buttonScan.setEnabled(false);
                }
            } );
    Thanks for any help, or direction.

    I can't use Java7 and so SimpleFileVisitor is out of the question.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,423
    Rep Power
    20

    Default Re: More efficient way to find the path of all folders with a specific name

    Quote Originally Posted by ralph View Post
    This is a GUI.
    Which toolkit? AWT/Swing/SWT/JavaFX/other?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    ralph is offline Member
    Join Date
    Nov 2012
    Posts
    36
    Rep Power
    0

    Default Re: More efficient way to find the path of all folders with a specific name

    Quote Originally Posted by DarrylBurke View Post
    Which toolkit? AWT/Swing/SWT/JavaFX/other?

    db
    Ah, sorry, SWT

  4. #4
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,105
    Rep Power
    6

    Default Re: More efficient way to find the path of all folders with a specific name

    So basically you have some code that scans the entire C-drive for a specific file. Yeah that will take a little time to finish depending on the number of files and directories there are; it will get worse when you realize that there is more than one drive and you'd need to scan them all. Using a FileFilter or a FilenameFilter may help a little.

    So what is it that you want to achieve? The user should still be able to do something with the GUI while the computer is digging around in the harddrive?
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  5. #5
    ralph is offline Member
    Join Date
    Nov 2012
    Posts
    36
    Rep Power
    0

    Default Re: More efficient way to find the path of all folders with a specific name

    I basically want to locate all of the ColdFusion servers within a persons computer and display the paths to them in a drop-down box so they can select each one and then perform certain actions on it.

    Whatever the path to the server is, all CF servers are located in a folder named "wwwroot" or "cfusion.war" so locating these seemed like the best solution of obtaining paths to all the servers.

    It's currently just a button that does just this (But as you mentioned, scans the entire drive folder by folder, and takes a while). It also doesn't allow the user to do anything during the scan. It freezes up and if the user clicks anything which the search is happening the window "Is not responding".

    Before the button I had the scan happen as soon as the program began, but that froze up the program at the start and took a long time to start up.

    here's the code for the button:
    Java Code:
    buttonScan = new Button( composite, SWT.NONE );
            buttonScan.setText( "Scan" );
            buttonScan.setEnabled( true );
            buttonScan.setToolTipText( "Click here to scan for CFML Server Folders" );
            buttonScan.setLayoutData( gridDataScan );
            
            buttonScan.addSelectionListener( new SelectionAdapter()
            {
                public void widgetSelected( SelectionEvent e )
                {
                	String nam = "C:/";
            	    File aFile = new File(nam);
            	    Process(aFile);
            	    buttonScan.setEnabled(false);
                }
            } );
    Last edited by ralph; 08-27-2013 at 04:53 PM.

  6. #6
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,105
    Rep Power
    6

    Default Re: More efficient way to find the path of all folders with a specific name

    I don't know too much about SWT, but for a Swing application you'd run the scan in a separate thread so it doesn't execute on the thread that handles all the GUI update events; likely you are experiencing the same problem here.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  7. #7
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,423
    Rep Power
    20

    Default Re: More efficient way to find the path of all folders with a specific name

    Quote Originally Posted by ralph View Post
    Ah, sorry, SWT
    Moved from New to Java.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  8. #8
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,786
    Rep Power
    5

    Default Re: More efficient way to find the path of all folders with a specific name

    I agree. And assuming your Process method does not run in its own thread, I would bet that your scan button is never disabled until after the process is complete (which is probably not what you want). Ideally, I would think you would do the scan in a thread, then simply change the button to something that lets you cancel the scan, if desired.

    In general, you should minimize the amount of processing you do on the Event Dispatch Thread.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  9. #9
    ralph is offline Member
    Join Date
    Nov 2012
    Posts
    36
    Rep Power
    0

    Default Re: More efficient way to find the path of all folders with a specific name

    Ah-ha, that's exactly what I wanted :)!

    When the page is first ran, I ran the Process method in it's own thread and went from there :)

    It now scans in the background while the user can still use the Application.

    Thanks a bunch! +rep to you both

Similar Threads

  1. Create folders dynamically in diff system (known path + IP)
    By wiki.horizon in forum Advanced Java
    Replies: 5
    Last Post: 06-28-2011, 10:29 AM
  2. How to find specific text from .txt file
    By krechlich in forum New To Java
    Replies: 11
    Last Post: 03-18-2011, 07:57 AM
  3. Displaying specific folders in JTree
    By LianaN in forum New To Java
    Replies: 2
    Last Post: 09-17-2010, 05:06 PM
  4. How do you find the OS specific linebreaker?
    By Addez in forum New To Java
    Replies: 1
    Last Post: 10-29-2009, 10:06 PM
  5. Replies: 4
    Last Post: 10-10-2009, 01:26 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •