Searching subdirectories

hi can anyone take a look at this code and tell me how to correct it. i am trying to search a directory and sub folders within it.
public ArrayList<File> arrfiles = new ArrayList<File>();
public File[] list =  null;      
public  ArrayList<File> listfiles(File folder){         
     try{
          list = folder.listFiles();
          for(int i = 0; i < list.length; i++){
               File file = list;
               if(file.isFile()){
                    arrfiles.add(file);
               else if(file.isDirectory()){
                    listfiles(file);
     catch(Exception e){
          System.out.print("Error" + e.toString());
     return arrfiles;
}problem is variable 'list' is overwritten every time there is a recursive call..                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

For one thing, neither arrfiles nor list should be defined as class members outside of that method. That is not making for a good clean API, as you are making listfiles() depend on state before invoking it.
Instead, you should do it more like this (taking your existing code and just slightly modifying it):
// remove arrfiles and list variables...
public  ArrayList<File> listfiles(File folder){         
  ArrayList<File> arrfiles = new ArrayList<File>(); // declare and initialise here
  try{
    File[] list = folder.listFiles(); // declare and initialise here
    for(int i = 0; i < list.length; i++){
      File file = list;
if(file.isFile()){
arrfiles.add(file);
else if(file.isDirectory()){
arrfiles.addAll(listfiles(file)); // add returned list from recursive call into the list
catch(Exception e){
System.out.print("Error" + e.toString());
return arrfiles;

Similar Messages

  • TestStand 4.1.1 vi search path

        This is so low-level I'm almost embarassed to ask.  I'm using TestStand 4.1.1 over LabView 8.6, both of which are licensed as full development systems.
        In order for our organization to make better use of (non-NI or Labview) source control, we've created a common directory structure for several developers over several large TestStand/LabView projects.  This includes areas for "common VIs" that are reused across projects.  So I'm in the process of migrating a rather complex project into a new directory structure.  The sequences and VIs in question were working perfectly under TestStand 4.0/LabView 8.5 prior to this attempted migration.
       My test sequences (and sub-sequences) can't seem to find needed VIs, even though they exist in directories that are included in the search paths I configured.  (An annoying sub-problem is that TestStand appears to "hang" while the LabView interface underneath the TestStand window is prompting for a VI's location.  I have to click the LabView item in the Windows menu bar to get LabView "on top" and see what the problem is.)
       I've already added several paths to both the LabView and TestStand VI search paths, and I've even checked the "search subdirectories" box, but the items are not being found.  It's going to take weeks to lead TestStand and LabView by the nose to find all this stuff.
       I can't believe this would really be a bug.  I tried searching the forums for an answer and had no luck.  I can't be the first one with such a problem, so help me out with some search terms so I don't have to clutter the forum with such basic stuff.  Thanks.
    -M

    trosier, Neurotika,
    It appears as if LabVIEW is having trouble finding your VIs, not TestStand.  When TestStand loads the VI you have designated as a code module into memory, if you have the LabVIEW development environment designated in the LabVIEW adapter settings, we tell LabVIEW to load the VI via its ActiveX interface. 
    If TestStand is unable to find the top-level VI, you will see a dialog like this:
    If LabVIEW is unable to find a sub-VI, you will see a dialog like this:
    Notice that the TestStand dialog has an additional checkbox at the bottom that allows you to select an absolute path.  Also notice that TestStand specifies what file its looking for in the Files of Type box while LabVIEW allows you to choose All LabVIEW Files. Which dialog are you seeing?
    Another way to test this is to try to open one of your VIs from disk (by double-clicking on it).  If you get a Searching for SubVIs dialog, then it is LabVIEW that can not find the dependencies. 
    Or if you open the specify module pane of the sequence editor, if TestStand cannot find the top-level VI, you will see a file not found warning like this: 
    If TestStand can find the file, but LabVIEW cannot find a sub-VI, then you will not get a warning or error until the VI is loaded.
    The reason that this matters is that TestStand and LabVIEW do not share their search directory lists.  If you have moved files, you will need to know which application cannot find its files. 
    Message Edited by Josh W. on 04-23-2009 11:27 AM
    Josh W.
    Certified TestStand Architect
    Formerly blue
    Attachments:
    subVI not found by LabVIEW.JPG ‏31 KB
    TestStand file not found.JPG ‏7 KB
    VI not found by TestStand.JPG ‏31 KB

  • How to conf  in Hyperion, so the system couldn't login with the same user

    Hai.....
    how to configure in Hyperion, so the system couldn't login with the same user id in different machine ? (could you please provide me with detail step by step ? )
    rgds
    uka fp

    fane_j wrote:
    Sally R. wrote:
    Someone gave me a suggestion to go to the terminal and type in the following:
    ls /Users/Shared/.*.so
    This was published on MacWorld's site, and it's not a very good tip. Try this instead
    ls -la /Users/Shared/*.so
    Turns out I was wrong about that. Somebody else suggested something even more complicated and got this reply:
    By bastion
    Fri Feb 24 08:49:05 PST 2012
    PeterSParker said
    Your terminal statement has an extra "." in it that prevents it from working.
    Also, you should add the options -alR to show what is happening, and to search subdirectories.
    The revised command looks like this:
    ls -alR /Users/Shared/*.so
    The above is completely wrong. The command as shown in the article is appropriate.
    The "." is not extra and doesn't prevent the command from working. It's specifying that you're listing files that start with a period and end with ".so" with anything in between being matched.
    Because you're explicitly searching for things that start with "." you don't need the -a flag.
    Because you only care about simple existence and not any metadata you don't need -l.
    Because the files of interest are installed in /Users/Shared directly, and not subfolders thereof, you don't need -R.

  • Radeon 9250 Blue Screen on Shut Down

    Problem with Radeon 9250 graphics card -- blue screen on Start | Shut Down, PC will not shut down, instead reboots. Blue screen message:
    ati2dvag.dll
    TERMINAL_SERVER_DRIVER_MADE_INCORRECT_MEMORY_REFERENCEScreenshot
    Radeon beta windows 7 driver package did not help. Current driver v8.252.0.0 worked fine with Vista 32bit Home Premium. Physically removing 9250 from the PC and using onboard VGA eliminated the blue screen. Reinstalling 9250 brought back the blue screen.
    Thanks in advance.Windows 7 32bit Build 7000, Intel Celeron 3.33 GHZ, Intel 775 Chipset, PC Chips P23G (3.0) motherboard, 1GB Ram, Radeon 9250 driver v8.252.0.0

    bcm02809 said:
    I have a Radeon 9250 (Sapphire AGP model) working fine on my machine, though it took a while to figure it out.
    I think it's something to do with the driver you use, though it might be something funny like it's trying to read the secondary monitor output on the card.  If you used the Catalyst 8.x drivers for Vista they don't work either. I ended up going on the AMD/ATI website and grabbing the drivers for XP Pro/Home 32-bit and they worked for me.
    Try this: Grab this file - Drivers for Radeon 9250 - XP 32bit.  It's an auto-exec but won't run under Vista/Win7 so instead explore the file & pull the folders out to your desktop.  Next, open up your device manager, then properties for your 9250. On the driver tab hit "Update Driver" and follow the options to manually browse & install the driver yourself.  Browse to the folder you pulled out, make sure it's set to search subdirectories, then hit OK.  This should do it - the plug & play recognition of the card will kick in once the driver is found.  If you've done it right and your card has a secondary monitor output, you'll not only be able to boot without a blue screen but it should automatically find that second output as well.
    Thanks bcm02809. I have the PCI version and my current driver is the XP 32bit driver.

  • Select Directory 'Not Responding' - bug report

    Hi,
    I was editing a step and realized that I needed to add another search directory.
    After choosing 'Select Directory' and then 'Add...' TestStand appears to lock up.
    Actually it has not really locked up, but as Filemon shows, is iterating through every directory.
    After 15 minutes it finally allowed user interaction and I was able to drill down into the next folder.
    However the response was still sluggish each time I opened up a new folder in my attempt to reach the final directory.
    [I am still trying to get there.]
    So there are times when the Select Directory function gives an abnormal behavior.
    Ronnie
    Message Edited by Believer on 09-29-2009 01:29 PM
    TestStand 4.2.1, LabVIEW 2009, LabWindows/CVI 2009

    Richard,
    No, I wasn't adding C:\ to the list. However, when I 'Add...' a directory, the dialog box begins at C:\Documents and Settings\All Users\Documents\National Instruments, and I then went straight to C:\ in order to then get to Program Files\IVI etc.
    I agree that searches would take awhile if I had selected C:\ but I am simply trying to Add a directory.
    My point was that TestStand should not be searching directories while I am just trying to add a directory to the search path.
    The graphic above shows for sure that TestStand is scanning through directory structures for some reason while I am trying to do this.
    This to me is odd. Why should it scan at this point?
    The Search Subdirectories check box is not valid at this time because I am adding a new directory (see the above graphic).
    As it happens I have not been able to reproduce the behavior I mentioned above - although it has happened to me once before.
    Thanks for your help,
    Ronnie
    TestStand 4.2.1, LabVIEW 2009, LabWindows/CVI 2009

  • Deployment Utility can't find files

    One of the standard search directories is “Current workspace directory”.
    I’ve discovered that the Deployment Utility may or may not look there (regardless of whether it is checked), and it may or may not look in its subdirectories (regardless of whether “Search Subdirectories” is checked.
    It works OK on some of our computers, but not on others.
    In order to insure that the build always finds the files, I have to explicitly include in the search directories the folder that contains the .tsw file.
    Is there a way to force the Deployment Utility to really look in the “Current workspace directory”?

    The deployment utility will create a list of top-level files to deploy from a workspace, a directory or both. The distribution sources (workspace and directory) will only point to the root element which we will use to create the tree of files to include, these files will be specified with an absolute path to the file and we will not use the search directories to find them.
    During the analysis phase the deployment utility will find all the required top-level files for the deployment. If you selected to deploy files from a workspace, the deployment utility will iterate over every worskpace object in the workspace and call GetAbsolutePath to get its path. If the problem you are seeing is with top-level files, then I would recommend calling into this method to verify that the files are found in the correct location.
    Once we get all the absolute paths for the workspace objects we search those files, depending on their type. At this point things start getting a bit more complicated because of the large number of file types. If your workspace contains a sequence (we will find the path of the sequence by calling GetAbsolutePath on the workspace object, see the previous step), then we will analyze the sequence and for every step we will call the public API of its adapter to get the path; for example, for the LabVIEW adapter we will use VIPath and ProjectPath (in general, there are some special cases where we call other methods) to figure out which VI to deploy. If the problem is with one of your code modules I would recommend calling into the public path methods in the adapter that is calling into your code and making sure that the files are found in the correct location.
    Without more information about your problem it is hard to give you a good answer, because the deployment utility (and test systems in general) are complicated pieces of code that deal with a great deal of complexity. Some of the things that might help us give you a more specific answer to your problem are:
    What version of TestStand are you using?
    What kind of deployment are you creating (VIs, DLLs, .Net assemblies? Creating Packed Libraries? Sending to multiple destinations?)?
    Can you simplify the test case so that we can reproduce with relatively few files? Could you provide a sample that shows the error?
    Are there any differences that you can think of between the computers where the deployment works and the computers where it doesn't?
    When is the error happening? What is happening exactly? For example: Are you getting an error in TSDU that says that files couldn't be found? Are you building the deployment and the files don't show up in the image directory? 
    I hope this helps.
    - Francisco

  • Very slow TestStand

    My TestStand was working fine for some time but lately it is very, very slow. Even if I create a brand new, empty sequence and start going to StationGlobals, then back to sequence, to types, even using menu items - all is very slow - I keep seeing the hour glass for between 5 to 15 seconds before actual action is performed by TestStand.
    And I tried the above with ONLY TesStand running - no other apps - same behavior. I have 256 MB RAM and Pentium 3, WINDOWS 2000 PRO.
    Other people in our company use the same WIN 2000 and very similar hardware and have normal performance.
    Any hints will be appreciated.

    First, use task manager to double check that some other process isn't hogging the CPU. If that is not the case another thing to check is your search directories. Go to Configure>>Search Directories in the sequence editor. Remove any directories you have added, especially to network drives or other potentially slow volumes, or to large directories with the search subdirectories option enabled. If that fixes it, add your paths back at the end of the list and put the slowest volumes or the directories with the largest amount of subdirectories to search at the very end. Hope this helps.

  • TestStand Deployment 5-7 hours?

    I've been trying to deploy my TestStand system for hte better part of a week, and I am losing patience.  I have deployed a few systems in the last few years, but this one has been difficult.  I am deploying the sequence and the engine/drivers separately.  The engine/drivers deployment builds quickly, so no problems there.  The sequence build takes 5-7 hours to build with most of the time "Updating file Links..."  I have confirmed that all sequence call pathnames specify <Current Sequence File>.  My main sequence has 47 sub-sequences (sequence calls), and my total number of steps is 699.  When built, there are 69 support VIs.  I don't use an ExpressVIs.
    I've done previous builds on another system with similar tests, but the sequence-only builds took < 1 hour.
    I am looking for suggestions on how to decrease the build time.  Perhaps I am overlooking something that would cause the deployment ot build so slowly. 
    Thank you
    Solved!
    Go to Solution.

    Hey TBone,
    A couple thoughts.
    Are you using source code control?  If so then I've seen issues similar to yours due to search directories.  The linking took forever because it seemed to be finding VIs through the network path and through the drive that was mapped.  It seemed like it was getting confused and kept relinking the same VI over and over.  Because it saw them at different paths.  Kinda like in a semi-infinite loop.  It was weird.  I refined my search directories to point to specific folders (a pain) but it went a whole lot quicker.
    Check your search directories and make sure they are set up correctly.  If you have a directory with tons and tons of children and you have selected search subdirectories then it could take forever.  Also if you have search directories that are pointing to similar folders just in different ways (i.e. through a mapped drive or through a machine name) then you could see weird linking issues.
    If you aren't using any dependancies on a network then unplug your ethernet cable and try building.  See what happens then.
    Also, I highly recommend deleting any and all older deployments.  Because TestStand doesn't package anything up into binaries (i.e. it just copies VIs over) then what you could have is the deployment finding the VI in the original location as well as a deployment you built previously.  This will cause it to flip out and go into that weird semi-infinite linking loop.  If you don't want to delete them then make for sure that your search directories aren't pointing to old builds. 
    As a rule of thumb- never build to a folder where you have dependancies or source code.  Always build to a user folder that is not in your search directories.
    Cheers,
    jigg
    CTA, CLA
    teststandhelp.com
    ~Will work for kudos and/or BBQ~

  • Logging into teststand slow

    I have noticed a change in the time it takes to login to TestStand and to run sequences. Has anybody noticed a longer delay in which TestStand operates. I notice the speed of TestStand improves maybe 10-fold when it is disconnected from the network? (maybe it's just my network is slow)

    Check your search paths (Configure>>Search Directories) to make sure that you do not have any network paths in the list. This includes any network drives mapped to a local drive letter. If you must have a network path in the list, move it to the end of the list and make sure you do not select the Search Subdirectories option for the path unless you really need it.

  • How to verify that the system isn't infected with a virus

    Does anyone know how to check to see if your system has been infected with any type of malware? I read in an article at zdnet.com that there was a Mac OS X trojan spotted, but the article did not say how to locate whether or not you had been infected. I do not have a virus checker on my computer. Someone gave me a suggestion to go to the terminal and type in the following:
    ls /Users/Shared/.*.so
    Any comments?

    fane_j wrote:
    Sally R. wrote:
    Someone gave me a suggestion to go to the terminal and type in the following:
    ls /Users/Shared/.*.so
    This was published on MacWorld's site, and it's not a very good tip. Try this instead
    ls -la /Users/Shared/*.so
    Turns out I was wrong about that. Somebody else suggested something even more complicated and got this reply:
    By bastion
    Fri Feb 24 08:49:05 PST 2012
    PeterSParker said
    Your terminal statement has an extra "." in it that prevents it from working.
    Also, you should add the options -alR to show what is happening, and to search subdirectories.
    The revised command looks like this:
    ls -alR /Users/Shared/*.so
    The above is completely wrong. The command as shown in the article is appropriate.
    The "." is not extra and doesn't prevent the command from working. It's specifying that you're listing files that start with a period and end with ".so" with anything in between being matched.
    Because you're explicitly searching for things that start with "." you don't need the -a flag.
    Because you only care about simple existence and not any metadata you don't need -l.
    Because the files of interest are installed in /Users/Shared directly, and not subfolders thereof, you don't need -R.

  • How to search for file in a directory or subdirectories?

    I need ur help urgently. I'm currently doing a java project in which the program should be able to do file searching.
    For eg. if I key in a.jpg, it should display C:\pictures\a.jpg (a.jpg is stored in a folder called "pictures")
    But the problem is that my program is only able to search in the C drive only.
    If I move the file into a folder in the C drive, my program cannot detect this.
    Can you help me to solve this problem? I'm really looking forward for your reply.
    Thanks. Here are the codes.
    import java.io.*;
    import java.awt.*;
    class FindFile
         public static void main(String args[]) throws IOException
              //reads the user input
              BufferedReader userInput;
              while(true)
                        userInput = new BufferedReader(new InputStreamReader(System.in));
                        String s = userInput.readLine();
                        //quits the system               
                        if(s.equals("/quit"))
                             System.exit(0);
                        //if user does not key in anything, prompt msg appear
                        else if(s.equals(""))
                             System.out.println("Command Syntax: java ListFiles <filename>");
                             System.out.println("<filename> - The full name of a file and extension (i.e., test.txt)");
                        else if(userInput != null)
                             String t = "c:";
                             File f = new File(t);
                             String[] files = f.list();
                             char[] qwet;
                             boolean test = false;
                             //check for the file name and compare with the user input
                             for (int i = 0; i < files.length; i++)
                                  if(files.equals(s))
                                       System.out.println("");
                                       System.out.println("File Found");
                                       System.out.print("The File Found at This Path: ");
                                       //display the path
                                       System.out.print(f.getAbsolutePath());
                                       System.out.println(files[i]);
                                       test = true;
                                       break;
                             //if file does not exist
                             if(test == false)
                                  System.out.println("File Not Found");

    well, i think the best solution would be make a recursive search through the directory tree. I don't know if you are familiar to this, but the functions that searches for the file would look like this:
    public String searchFile(String name) {
      File[] roots = File.listRoots();   // List all file roots (in windows the different units, c:, d:, etc.)
      for (int i = 0 ; i < roots.length() ; i++) {
        String aux = recursiveSearch(roots, name);
    if (aux != null) {   // If the "recursiveSearch" returns something different than null is that the file is founded, so we return the path.
    return aux;
    return null; // If we get there nothing has been found
    private String recursiveSearch(File f, String name) {   // f is the directory to search for the file with name "name"
    File[] childs = f.listFiles();
    for (int i = 0 ;i < childs.length ; i++) {
    if (childs[i].isDirectory()) {  // If that is a directory we search inside
    String aux = recursiveSearch(childs[i], name);
    if (aux != null) {   // We have found it inside this directory
    return aux;
    } else {  // Is a regular file
    if (name.compareTo(childs[i].getName()) == 0) {   // If the file is what we want we return his path
    return childs[i].getCanonicalPath();
    // If we get here is because the file is not inside the directory or any subdirectory on it
    return null;
    You should just call the function searchFile(name) with the name of the file you want to search. If it finds one with this name it will return his absolute path, and if he doesn't the desired file he will return null.
    If you don't understand anything just ask.
    (Note: i have not tested this code, so can be some mistakes, but it think it is almost correct. mmmhh don't now why, but [ & ] appear in my code as < & >. Just replace them.).
    Hope that helps.
    Zerjio

  • Searching file from directory located at http path.

    Hi All,
    I have made the program to search for a file in a directory and its subdirectories. This is working fine when my directory is located on local machine. But if the same directory is placed in HTTP path, the code fails to search a directory. Does anyone has idea how can i connect to site so as to access the directories. I used URL and URLConnection to read and write file to the site, and this is also working fine but when it comes to directories i find no solution. Please help.

    This works fine if i map http://flash/ on my C: and
    try to list files in directory C:\Mojo. Can you please
    tell how can i know whether the http server i am
    trying to access allows directory listing or not.
    Because if it does not i have administrator rights on
    the server and i can make the changes required.You can see if your Web server allows directory listing by simply
    typing in the URL you want to examine, inside your browser, and see if
    it shows you a directory listing. For instance, if you type in:
    http://flash/Mojo/
    in your browser's address bar, and you see a list of files in that
    directory, then your Web server supports directory listing.
    Note, though, that you can't use the File list() method to get a list of files.
    You'll have to make a connection, read the input stream, and then parse
    the filenames out of the HTML that the Web server returns. (You can see
    what the HTML looks like, by doing View Source inside your brower. That's
    what you'll get back from your Java program.)
    --Steve

  • How to customize search in WS 7 and for multiple virtual servers?

    I'm not clear on how to customize search results pages in Sun Web Server 7. The documentation (the Adminstrator's Guide, page 215) says:
    You can take a look at the default search application located at /bin/https/webapps/search as a sample application
    but I'm not seeing any such thing. I did a find . -name search -type d from the server root and instance root but the only search directories I'm seeing are subdirectories within the generated directory and they look like system generated jsps that I shouldn't touch (So I didn't :-)
    So one question is, where is the default app? A second question is, how do we set up different branding for different virtual servers?
    We're currently using WS 6.1 and it has a field in the GUI for the directory containing the web app to use for search. That seems to have disappeared in WS 7.
    Any help would be appreciated. Thanks.
    Dave

    I don't use the search engine, so I'm afriad I don't have direct experience here.
    What I'd probably do is modify the app so that it looks at the Host data to determine which directory it should point to for graphics, formatting, etc. You could also use the obj.conf with variables to pull graphics from directories appropriately branded. Something like:
    1) Create "additional doc directory" for images
    2) Find the entry in the obj.conf that points to the new directory
    3) Modify the path to something like /path/to/$host/images
    4) Make sure you create directories like:
    /path/to/foobar.com/images/
    /path/to/www.foobar.com/images/
    /path/to/baz.com/images/
    /path/to/www.baz.com/images/

  • Acrobat Pro Extended 9 crashes when searching large directory

    I use the "Edit - Search - All PDF Documents in" Search capabilities a lot and it crashes every time. A recent crash occurred after reaching 320 hits in 65 documents in a directory with over 2250 documents (including subdirectories).

    One of our users is having a similar problem.    He always leaves Elements open in the background so I'm wondering if this is causing problems when he downloads and opens pdfs using Acrobat Standard 9.  He also seeing the images stretch to the point of seeing a bunch of horizontal lines.  Has anyone offered any solutions?

  • Using subdirectories in file sender

    Hi there
    Is is possible to search in all subdirectories in your file sender adapter's source directory? I know you can specify the different directories using the Advance Selection for Source File but i'd like to know if you can specify somehow to have it search the source directory and all it's subdirectories?
    Thanks,
    Jan

    There is no standard way to do this. You may however have some OS script to perform this. The script may search the file and copy it at one location from where PI can pick it up.
    Regards,
    Prateek

Maybe you are looking for