Nov 6, 2004 #1 chessbot Programmer Mar 14, 2004 1,524 US Is there a way to loop through all the files in a directory without knowing their names? Thanks! --Chessbot "See the TURTLE of enormous girth!" -- Stephen King, The Dark Tower series
Is there a way to loop through all the files in a directory without knowing their names? Thanks! --Chessbot "See the TURTLE of enormous girth!" -- Stephen King, The Dark Tower series
Nov 6, 2004 1 #2 sedj Programmer Aug 6, 2002 5,610 File dir = new File("the_dir"); File[] files = dir.listFiles(); for (int i = 0; i < files.length; i++) { System.out.println(files); } You should use a recursive method to loop through all subdirectories ... -------------------------------------------------- Free Database Connection Pooling Software http://www.primrose.org.uk Upvote 0 Downvote
File dir = new File("the_dir"); File[] files = dir.listFiles(); for (int i = 0; i < files.length; i++) { System.out.println(files); } You should use a recursive method to loop through all subdirectories ... -------------------------------------------------- Free Database Connection Pooling Software http://www.primrose.org.uk
Nov 6, 2004 Thread starter #3 chessbot Programmer Mar 14, 2004 1,524 US Thanks! Is there a way to take files only of a certain extension, rather than loading them all in and checking? --Chessbot "See the TURTLE of enormous girth!" -- Stephen King, The Dark Tower series Upvote 0 Downvote
Thanks! Is there a way to take files only of a certain extension, rather than loading them all in and checking? --Chessbot "See the TURTLE of enormous girth!" -- Stephen King, The Dark Tower series
Nov 7, 2004 #4 sedj Programmer Aug 6, 2002 5,610 Implement the FileFilter class, and use the File.listFiles(FileFilter filter) method. http://java.sun.com/j2se/1.4.2/docs/api/java/io/FileFilter.html -------------------------------------------------- Free Database Connection Pooling Software http://www.primrose.org.uk Upvote 0 Downvote
Implement the FileFilter class, and use the File.listFiles(FileFilter filter) method. http://java.sun.com/j2se/1.4.2/docs/api/java/io/FileFilter.html -------------------------------------------------- Free Database Connection Pooling Software http://www.primrose.org.uk
Nov 7, 2004 Thread starter #5 chessbot Programmer Mar 14, 2004 1,524 US Thank you! Is there any better way to do this than Code: // ... public boolean accept(File f) { return (f.getName().endsWith(".ext")); } // ... --Chessbot "See the TURTLE of enormous girth!" -- Stephen King, The Dark Tower series Upvote 0 Downvote
Thank you! Is there any better way to do this than Code: // ... public boolean accept(File f) { return (f.getName().endsWith(".ext")); } // ... --Chessbot "See the TURTLE of enormous girth!" -- Stephen King, The Dark Tower series
Nov 8, 2004 #6 sedj Programmer Aug 6, 2002 5,610 Thats how you would do it ... -------------------------------------------------- Free Database Connection Pooling Software http://www.primrose.org.uk Upvote 0 Downvote
Thats how you would do it ... -------------------------------------------------- Free Database Connection Pooling Software http://www.primrose.org.uk
Nov 8, 2004 Thread starter #7 chessbot Programmer Mar 14, 2004 1,524 US OK good. Just wondering if RegEx would be better... --Chessbot "See the TURTLE of enormous girth!" -- Stephen King, The Dark Tower series Upvote 0 Downvote
OK good. Just wondering if RegEx would be better... --Chessbot "See the TURTLE of enormous girth!" -- Stephen King, The Dark Tower series