commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Jakarta-commons Wiki] Update of "VfsFaq" by MarioIvankovits
Date Mon, 13 Feb 2006 14:35:38 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Jakarta-commons Wiki" for change notification.

The following page has been changed by MarioIvankovits:
http://wiki.apache.org/jakarta-commons/VfsFaq

------------------------------------------------------------------------------
  FileObject fo = VFS.getManager().resolveFile("ftp://host/path_to/file.txt", opts);
  }}}
  
+ == How to use the org.apache.commons.vfs.FileSelector or org.apache.commons.vfs.FileFilter
==
+ 
+ The FileFilter can be used to mimic the java.io.FileFilter interface.
+ 
+ {{{
+ FileFilter ff = new FileFilter()
+ {
+     public boolean accept(FileSelectInfo fileInfo)
+     {
+         FileObject fo = fileInfo.getFile();
+         return fo.getName().getBaseName().startsWith("ABC-");
+     }
+     		
+ };
+ VFS.getManager().resolveFile("/base/folder").findFiles(new FileFilterSelector(ff));
+ }}}
+ 
+ You should consider using the more VFS native org.apache.commons.vfs.FileSelector interface
as this allows you to automatically traverse recursive.
+ 
+ Available FileSelectors:
+  * AllFileSelector - select all files
+  * FileDepthSelector - select files at a given depth range
+  * FileTypeSelector - select files by type (file, folder)
+ 
+ So the following will be the same as above, but will scan the whole tree starting at the
base folder.
+ 
+ {{{
+ FileSelector ff = new FileSelector()
+ {
+     public boolean includeFile(FileSelectInfo fileInfo) throws Exception
+     {
+         FileObject fo = fileInfo.getFile();
+         return fo.getName().getBaseName().startsWith("ABC-");
+     }
+ 
+     public boolean traverseDescendents(FileSelectInfo fileInfo) throws Exception
+     {
+         return true;
+     }   		
+ };
+ VFS.getManager().resolveFile("/base/folder").findFiles(ff);
+ }}}
+ 

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message