Hi all,
I have built some code that prints out directory files and non-diectory files. I want to get some help in indenting my code further to achieve level 5 indentation or further since now its up to2. Any ideas please??
Below is the code.
I have 4 classes;
package com.Ronald.javafundamentals.FileIteration;
/**
*
*
*/
import java.io.*;
import java.io.File;
public class FileIterator
{
public void printContents(File folder,Boolean displayFiles,Boolean isSubDir)
{
String totalspace="";
String dirFilecount="";
String dirspace ="";
String filespace="";
DirUtils dirUtil=new DirUtils();
File[] directorys = folder.listFiles();
if (isSubDir)
{
dirspace =" ";
}
for(int i=0;i<directorys.length;i++)
{
if (dirUtil.isDirectory(directorys[i]))
{
totalspace=""+directorys[i].getTotalSpace();
dirFilecount=""+directorys[i].list().length;
System.out.println(dirspace+directorys[i].getName()+"(File count= "+ dirFilecount+" size="+totalspace+")");
//System.out.println("-------------------------------------");
printContents(directorys[i],displayFiles,true);
// dirspace=dirspace+ " ";
}
else
{
if (displayFiles==true)
{
System.out.println(dirspace + filespace+directorys[i].getName());
}
}
}
}
public static void main(String[]args) throws IOException
{
String x;
// TODO code application logic here
File rootFolder = new File("C:/Program Files");
FileIterator fi = new FileIterator();
System.out.println("Do you want the directories and files to be written out or just directories? (Y or N) ");
BufferedReader in= new BufferedReader(new InputStreamReader(System.in));
x=in.readLine();
if ((x.equalsIgnoreCase("N")) || (x.equalsIgnoreCase("n")))
{
fi.printContents(rootFolder,false,false);
}
else if ((x.equalsIgnoreCase("Y")) || (x.equalsIgnoreCase("y")))
{
fi.printContents(rootFolder,true,false);
}
else
{
System.out.println("sorry you entered a wrong value");
}
}
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.Ronald.javafundamentals.FileIteration;
/**
*
* @author Ronald Ojino
*/
import java.io.File;
import java.io.*;
public class DirUtils implements FileFilter
{
public boolean accept(File file)
{
return file.isFile();
}
public static boolean isDirectory(File file)
{
return file.isDirectory();
}
public static boolean isNotDirectory(File file)
{
return !file.isDirectory();
}
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.Ronald.javafundamentals.FileIteration;
/**
*
* @author Ronald Ojino
*/
import java.io.*;
import java.io.File;
public class IsDirectory implements FileFilter{
public boolean accept(File file)
{
return file.isDirectory();
}
}
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.Ronald.javafundamentals.FileIteration;
/**
*
* @author Ronald Ojino
*/
import java.io.File;
import java.io.*;
public class IsNotDirectory implements FileFilter
{
public boolean accept(File file)
{
return !file.isDirectory();
}
}