Quote:
|
Originally Posted by Belisarius
You probably haven't looked at the Javadocs for File. File can either represent a standard file, or a directory. If it's the latter, you can use the list() method to get an array of Strings listing the contents of the directory.
|
Cheers, had a wee blast and with some help i got this which works.
Code:
*/import java.io.*;
public class retrieveName {
/** Creates a new instance of retirveName */
public void listNames(String startName) {
File startFile = new File(startName);
File[] contents = startFile.listFiles();
if (contents == null) {
System.err.println("Could not list " + startFile);
return;
}
java.util.Arrays.sort(contents);
for (int i = 0; i < contents.length; i++) {
System.out.println(contents[i]);
}
public static void main(String[] args) {
try {
ListFileNames myList = new ListFileNames();
myList.listNames(".");
//myList.listNames(args[0]);
} catch (Exception e) {
System.err.println(e);
}
}
}
apologies for the bad indentation.
how do i catch what is in contents[i] and do something with each line of contents?
i.e my results are
./catF1.cyt
./catF1.jpg
./catF2.cyt
./catF2.jpg
i want to take each member of the list (ignoring the jpg files) and save the F1, F2 etc into an array of names.