1 23 24 29 30 package com.sun.enterprise.config.backup.util; 31 import java.io.*; 32 import java.util.*; 33 34 39 public abstract class FileLister 40 { 41 abstract protected boolean relativePath(); 42 43 45 FileLister(File root) 46 { 47 mainRoot = root; 48 fileList = new ArrayList(); 49 } 50 51 56 public void keepEmptyDirectories() 57 { 58 keepEmpty = true; 59 } 60 61 63 public String [] getFiles() 64 { 65 getFilesInternal(mainRoot); 66 String [] files = new String [fileList.size()]; 67 68 if(files.length <= 0) 69 return files; 70 71 int len = 0; 72 73 if(relativePath()) 74 len = mainRoot.getPath().length() + 1; 75 76 for(int i = 0; i < files.length; i++) 77 { 78 files[i] = ((File)fileList.get(i)).getPath().substring(len).replace('\\', '/'); 79 } 80 81 Arrays.sort(files, String.CASE_INSENSITIVE_ORDER); 82 return files; 83 } 84 85 87 private void getFilesInternal(File root) 88 { 89 File[] files = root.listFiles(); 90 91 for(int i = 0; i < files.length; i++) 92 { 93 if(files[i].isDirectory()) 94 { 95 getFilesInternal(files[i]); 96 } 97 else 98 fileList.add(files[i]); } 100 101 if(files.length <= 0 && keepEmpty) 103 fileList.add(root); 104 } 105 106 108 private ArrayList fileList = null; 109 private File mainRoot = null; 110 private boolean keepEmpty = false; 111 } 112 | Popular Tags |