+ Ignore initial CWD (there are stored the .jun-files, etc.)

! Path comparison is done with equalsIgnoreCase - so this will not work on UNIXish machines where the system differs between bla and blA+ Ignore initial CWD (b
This commit is contained in:
mbirth 2005-01-17 10:29:48 +00:00
parent 9ba7f24b48
commit 2946c6429e

View File

@ -15,10 +15,13 @@ public class MyFilesystemParser {
File logFile; File logFile;
private String curLine; private String curLine;
private String ignoreDir;
private long counter; private long counter;
public MyFilesystemParser(String logfile) { public MyFilesystemParser(String logfile) {
logFile = new File(logfile+".gz"); logFile = new File(logfile+".gz");
ignoreDir = System.getProperty("user.dir");
while (ignoreDir.charAt(ignoreDir.length()-1)=='\\') ignoreDir = ignoreDir.substring(0, ignoreDir.length()-1);
} }
public boolean driveIsWritable(char drive) { public boolean driveIsWritable(char drive) {
@ -55,14 +58,21 @@ public class MyFilesystemParser {
return result; return result;
} }
/** Returns all files of a specified directory */ /** Returns all files of a specified directory
public File[] listFiles(File dir) { ATTENTION! ignoreDir has to contain a directory which should be ignored (temp, etc.).
The String must have no trailing backslash or slash. Also keep in mind that we work with
equalsIgnoreCase - so this won't work correctly on UNIXish machines
@param dir Directory to get contents of
@param noIgnoreDir If false, the startup-directory is ignored (because there are temporary files, data files, etc.)
@return File[] with File-Objects of all files in that directory
*/
public File[] listFiles(File dir, boolean noIgnoreDir) {
String[] files = dir.list(); String[] files = dir.list();
File[] result; File[] result;
if (files != null) { if ( files != null && ( !dir.getAbsolutePath().equalsIgnoreCase(ignoreDir) || noIgnoreDir )) {
result = new File[files.length]; result = new File[files.length];
for (int i=0; i<files.length; i++) { for (int i=0; i<files.length; i++) {
String lastItem = dir.getPath(); String lastItem = dir.getAbsolutePath();
result[i] = new File(lastItem+((lastItem.charAt(lastItem.length()-1)=='\\')?"":"\\")+files[i]); result[i] = new File(lastItem+((lastItem.charAt(lastItem.length()-1)=='\\')?"":"\\")+files[i]);
} }
} else { } else {
@ -136,7 +146,7 @@ public class MyFilesystemParser {
/** Writes all file-entries incl. size and time of dir and sub-dirs to fw */ /** Writes all file-entries incl. size and time of dir and sub-dirs to fw */
public void dumpFiles(BufferedOutputStream fw, File dir) throws IOException { public void dumpFiles(BufferedOutputStream fw, File dir) throws IOException {
File[] entries = sortDir(listFiles(dir)); File[] entries = sortDir(listFiles(dir, false));
for (int i=0; i<entries.length; i++) { for (int i=0; i<entries.length; i++) {
if (entries[i].isDirectory() && entries[i].canRead()) { if (entries[i].isDirectory() && entries[i].canRead()) {
fw.flush(); fw.flush();
@ -162,7 +172,7 @@ public class MyFilesystemParser {
/** Compares file-liste from cmp to actual files on disk and writes changes to out */ /** Compares file-liste from cmp to actual files on disk and writes changes to out */
public void cmpFiles(BufferedReader cmp, BufferedOutputStream out, File dir, BufferedOutputStream dout) throws IOException { public void cmpFiles(BufferedReader cmp, BufferedOutputStream out, File dir, BufferedOutputStream dout) throws IOException {
File[] entries = sortDir(listFiles(dir)); File[] entries = sortDir(listFiles(dir, false));
String myLine = ""; String myLine = "";
for (int i=0; i<entries.length; i++) { for (int i=0; i<entries.length; i++) {
if (entries[i].isDirectory() && entries[i].canRead()) { if (entries[i].isDirectory() && entries[i].canRead()) {
@ -285,7 +295,7 @@ public class MyFilesystemParser {
/** Returns a list of data files */ /** Returns a list of data files */
public String[] getMonitored(String mask) { public String[] getMonitored(String mask) {
File[] files = sortDir(listFiles(new File(".\\"))); File[] files = sortDir(listFiles(new File("."), true));
String fn = ""; String fn = "";
String[] result = new String[0]; String[] result = new String[0];
String[] tmp; String[] tmp;