How do I select files to a particular depth in a directory?
Author: Deron Eriksson
Description: This Java tutorial describes how to select files down to a particular depth in a directory using Commons IO.
Tutorial created using:
Windows XP || JDK 1.5.0_09 || Eclipse Web Tools Platform 2.0 (Eclipse 3.3.0)
(Continued from page 1) The contents of my project, with the "stuff" directory expanded, is shown below: The console output from the execution of DirectoryWalkerTest is shown below. You can see that only *.txt files at a depth of 3 or less in the "stuff" directory get put in the list of files obtained by the walker. Resultsdepth is 2, so C:\projects\workspace\testing\stuff\f1\a.txt will be added file doesn't end in .txt, so C:\projects\workspace\testing\stuff\f1\e.jsp will be skipped depth is 3, so C:\projects\workspace\testing\stuff\f1\f2\b.txt will be added depth is 4, so C:\projects\workspace\testing\stuff\f1\f2\f3\c.txt will be skipped depth is 5, so C:\projects\workspace\testing\stuff\f1\f2\f3\f4\d.txt will be skipped file doesn't end in .txt, so C:\projects\workspace\testing\stuff\f5\f.jsp will be skipped depth is 3, so C:\projects\workspace\testing\stuff\f5\f6\g.txt will be added depth is 2, so C:\projects\workspace\testing\stuff\f7\h.txt will be added Files ending with .txt with a depth of 3 or less file:C:\projects\workspace\testing\stuff\f1\a.txt file:C:\projects\workspace\testing\stuff\f1\f2\b.txt file:C:\projects\workspace\testing\stuff\f5\f6\g.txt file:C:\projects\workspace\testing\stuff\f7\h.txt Related Tutorials:
|