i am trying to write a method that searches a directory (plus subdirs) for a file and returns true when a file that matches the given pattern was found. otherwise it should return false. the head should look like this:
i have no idea how to do that.
do you have an idea?
THANKS [ June 08, 2004: Message edited by: Andreas Golchert ]
I'm going to outline some suggested steps. If I name a step that you need technical help with, holla.
create a method that does the following:
1. given the name of a directory, create a File object that points to that directory.
2. list all the files contained in that directory. 2. 1 If a given sub file is not a directory, then check to see if it's the one you want. if yes, return a new File object that points to the target. if not, check the other non-directory files. If the file you're looking for isn't there, return null.
Once you have this done, let me know. The next step will be amazingly simple
it looks good . I've rounded it out in the example below, so it searches sub directories also. Notice, this isn't the style I would code it, but I wanted to be consistent with your coding style, so there would be one less barrier.
As an alternative, you could explore the FilenameFilter class so you only get directories (for recursion) and files matching your pattern back - when File has these filtering facilities in place it seems a bit of a pity not to use them. Although truth be told I can't say the code gets any simpler As a point of style, when you need to turn stuff into a String, consider using toString() or (if the object may be null) String.valueOf(). It's a clearer statement of intent than concatenating with "", and more efficient too.