feedme java project

is free software, licensed under the terms of the GNU General Public License, that feeds/imports media from anywhere to xbox360 media center extenders, ipods, web servers, file servers, etc. using Java.

Please read the license here.

Wednesday, August 15, 2007

public class feedDirList


public class feedDirList {

File directory;
int indent = 2;
static Vector feed = new Vector();

public static void main(String[] args) {
try {
for (int i = 0; i < args.length; i++) {
DirList dl = new DirList(args[i]);
dl.list();
}
}
catch (IOException e) {
System.err.println(e);
}

}

public DirList(String s) throws IOException {
this(new File(s), 2);
}

public DirList(File f) throws IOException {
this(f, 2);
}

public DirList(File directory, int indent) throws IOException {
if (directory.isDirectory()) {
this.directory = new File(directory.getCanonicalPath());
}
else {
throw new IOException(directory.toString() + " is not a directory");
}
this.indent = indent;
String spaces = "";
for (int i = 0; i < indent-2; i++) spaces += " ";
System.out.println(spaces + directory + File.separatorChar);
}

public void list() throws IOException {

if (!feed.contains(this.directory)) {
feed.addElement(this.directory);
String[] files = directory.list();
String spaces = "";
for (int i = 0; i < indent; i++) spaces += " ";
for (int i = 0; i < files.length; i++) {
File f = new File(directory, files[i]);
if (f.isFile()) {
System.out.println(spaces + f.getName());
}
else { // it's another directory
DirList dl = new DirList(f, indent + 2);
dl.list();
}
}
}

}

}

No comments: