4 import java.io.FilenameFilter;
6 public class BackupFileFilter implements FilenameFilter
11 public String template;
15 public String extension;
17 public BackupFileFilter(String base, String template, int digits,
21 this.template = template;
23 this.extension = extension;
27 public boolean accept(File file, String filename)
29 if (file.isDirectory())
35 int numcharstart = template.indexOf(BackupFiles.NUM_PLACEHOLDER);
36 String templateStart = template;
37 String templateEnd = "";
38 if (numcharstart > -1)
40 templateStart = template.substring(0, numcharstart);
41 templateEnd = template.substring(numcharstart + BackupFiles.NUM_PLACEHOLDER.length());
43 int startLength = base.length() + templateStart.length();
44 int endLength = templateEnd.length() + extension.length();
45 if (filename.length() == startLength + digits + endLength
46 && filename.startsWith(base + templateStart)
47 && filename.endsWith(templateEnd + extension)
49 .substring(startLength,
50 filename.length() - endLength + 1)