1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
| public class Lister_Rep {
private String initialpath = "";
private Boolean recursivePath = false;
public int filecount = 0;
public int dircount = 0;
ArrayList<String> fichier=new ArrayList<String>();
public Lister_Rep(String path, Boolean subFolder) {
super();
this.initialpath = path;
this.recursivePath = subFolder;
}
Lister_Rep() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
public ArrayList<String> Lister_Rep() {
this.listDirectory(this.initialpath);
return fichier;
}
public ArrayList<String> listDirectory(String dir) {
File file = new File(dir);
File[] files = file.listFiles();
if (files != null) {
for (int i = 0; i < files.length; i++) {
if (files[i].isDirectory() == true) {System.out.println("Dossier: " + files[i].getAbsolutePath());fichier.add(files[i].getName());}
if(files[i].isDirectory() == true && this.recursivePath == true) {
this.listDirectory(files[i].getAbsolutePath());
}
else {
System.out.println("nb:"+filecount++);}
}}
return fichier;
public static void main( String [] args ) throws FileNotFoundException{
Lister_path disk = new Lister_path(pathlist, true);
ArrayList<String> resultat = disk.Lister_path();}} |
Partager