1 package net.sourceforge.phpeclipse.mover;
4 import java.io.IOException;
6 public class DirectoryWalker {
8 protected IMover[] fMover;
9 protected IFilter[] fFilter;
11 * creates a new DirectoryWalker
12 * mover and filter array should have the same length !
14 public DirectoryWalker(IMover[] mover, IFilter[] filter) {
16 this.fFilter = filter;
20 * creates a new DirectoryWalker with a IFilter.DEFAULT_FILTER
22 public DirectoryWalker(IMover[] mover) {
24 this.fFilter = new IFilter[mover.length];
25 for (int i = 0; i < mover.length; i++) {
26 this.fFilter[i] = IFilter.DEFAULT_FILTER;
30 * walks through the source directory, processing files as it
31 * goes along to create the target directory
32 * @param source source directory
33 * @param target target directory
34 * @throws IOException error with the file system
35 * @throws XMException error caught by the application
37 public void walk(String source, String target) throws IOException {
40 walk(new File(source), new File(target));
47 * actual implementation of the walking
48 * @param source source directory
49 * @param target target directory
50 * @throws IOException error with the file system
51 * @return true if walking should continue, false if the messenger
52 * has asked for the end of the walking
54 protected boolean walk(File source, File target) throws IOException {
56 if (!(target.exists() && target.isDirectory()))
60 for (int j = 0; j < fMover.length; j++) {
63 int idirs = 0, idocs = 0;
64 if (source.isDirectory()) {
65 File[] files = source.listFiles();
66 dirs = new File[files.length];
67 docs = new File[files.length];
70 for (int i = 0; i < files.length; i++) {
71 if (files[i].isDirectory()) {
72 if (fFilter[j].isDirectoryOk(files[i])) {
73 dirs[idirs++] = files[i];
75 } else if (files[i].isFile()) {
76 if (fFilter[j].isFileOk(files[i])) {
77 docs[idocs++] = files[i];
89 for (int i = 0; i < idocs; i++) {
90 System.out.println(docs[i].getAbsolutePath());
92 File result = fMover[j].move(docs[i], target);
95 System.out.println("directories");
96 for (int i = 0; i < idirs; i++) {
97 System.out.println(dirs[i].getAbsolutePath());
98 if (!walk(dirs[i], new File(target, dirs[i].getName())))