P
P.Hill
Greetings Java Folks,
I as writting a class that was processing a list of files.
Given an arbitrary file spec that looked like:
/incoming/projectData*.dat
The last splat in this case is actually a time stamp.
but now I need to complicate things by searching for
/incoming/*/projectData*.dat
Where the first splat is a userDir.
Anyone know of code that can help me with this?
Using generic stuff out of the JDK, I was playing with
File.fileList and a FileFilter, creating my special
FileFilter which has an accept method that looks like:
public boolean accept(File file) {
String filepath = file.getPath();
if ( filepath.startsWith( this.lefthand ) &&
filepath.endsWith( this.righthand ) ) {
return true;
}
return false;
}
Simple enough, but am I missing something somewhere else
for doing this type of generic filtering?
Why do I ask? Well we've realized we want to change
the code to deal with /incoming/*/projectData*.dat
Now I COULD use the existing code by telling
working this second spec. to put both username
and the date into the last splat, but for external
reason (other code) I think I'll stick to
the form /incoming/*/projectData*.dat
Is there anything in the JDK or elsewhere that I've overlooked that helps
me more than FileFilter to do a fancier job than the above FileFilter of
doing such wildcard matches? How about combining FileFilter with
Reg. Expressions? Never used that, but it looks like something like:
Pattern pattern = Pattern.compile( "/incoming/*/projectData*.dat" );
this.matcher = pattern.matcher( "" ); // start with no candidate string.
....
and then in accept( File file) I do:
String filepath = file.getPath();
this.matcher.reset( filepath );
boolean goodFile = this.matcher.matches();
if ( goodFile ) return true;
That look good to everyone?
It seems pretty good, but then I also have to find all
dirs in the /incoming/ directory looping through those
to to get a fileList from each.
None of this is rocket science, but it seems to be a well traveled
path. Anyone know of code that does more of the work for me instead
of working up a set of two calls to filePath?
Let me know, if you do, or if you have other ideas, meanwhile I'll
be coding the fileSet of dir's followed by the fileset from each
dir solution.
TIA,
-Paul
I as writting a class that was processing a list of files.
Given an arbitrary file spec that looked like:
/incoming/projectData*.dat
The last splat in this case is actually a time stamp.
but now I need to complicate things by searching for
/incoming/*/projectData*.dat
Where the first splat is a userDir.
Anyone know of code that can help me with this?
Using generic stuff out of the JDK, I was playing with
File.fileList and a FileFilter, creating my special
FileFilter which has an accept method that looks like:
public boolean accept(File file) {
String filepath = file.getPath();
if ( filepath.startsWith( this.lefthand ) &&
filepath.endsWith( this.righthand ) ) {
return true;
}
return false;
}
Simple enough, but am I missing something somewhere else
for doing this type of generic filtering?
Why do I ask? Well we've realized we want to change
the code to deal with /incoming/*/projectData*.dat
Now I COULD use the existing code by telling
working this second spec. to put both username
and the date into the last splat, but for external
reason (other code) I think I'll stick to
the form /incoming/*/projectData*.dat
Is there anything in the JDK or elsewhere that I've overlooked that helps
me more than FileFilter to do a fancier job than the above FileFilter of
doing such wildcard matches? How about combining FileFilter with
Reg. Expressions? Never used that, but it looks like something like:
Pattern pattern = Pattern.compile( "/incoming/*/projectData*.dat" );
this.matcher = pattern.matcher( "" ); // start with no candidate string.
....
and then in accept( File file) I do:
String filepath = file.getPath();
this.matcher.reset( filepath );
boolean goodFile = this.matcher.matches();
if ( goodFile ) return true;
That look good to everyone?
It seems pretty good, but then I also have to find all
dirs in the /incoming/ directory looping through those
to to get a fileList from each.
None of this is rocket science, but it seems to be a well traveled
path. Anyone know of code that does more of the work for me instead
of working up a set of two calls to filePath?
Let me know, if you do, or if you have other ideas, meanwhile I'll
be coding the fileSet of dir's followed by the fileset from each
dir solution.
TIA,
-Paul