import java.io.File;

public class MyFileSystem
{
	// step 1. main method can be done first
	public static void main (String[] args)
	{
		String dirName;
		
		if (args.length == 0 )  
			dirName = ".";
		else
			dirName = args[0]; //pathname ? or not?
			
		File dir = new File (dirName);
		listAll (dir);
		//step 6. size calculation call method below
		System.out.println("Total bytes: " + size(dir));

	}
	
	//step 2. public driver
	public static void listAll (File dir)  
	{
		listAll (dir, 0);
	}
	
	//step 3. recursive method to list all files in directory
	private static void listAll (File dir, int depth)
	{
		printName (dir.getName(), depth);
		//step 5. recursive call to listAll itself
		if (dir.isDirectory())
		{	
			for (File child : dir.listFiles())
				listAll (child, depth+1);
		}
	}
	
	//step 4. used by listAll
	public static void printName (String name, int depth)
	{
		for (int i = 0; i < depth; i++ ) 
			System.out.print ("   ");
		System.out.println(name);
	}
	
	//step 7. size calculation
	public static long size (File dir)
	{
		long totalSize = dir.length ();//in bytes
		if (dir.isDirectory())
			for (File child : dir.listFiles() )
			{
				totalSize += size(child);
			}
		//System.out.println("<"+dir.getName()+">");
		//System.out.println("size of this file = " + dir.length());
		//System.out.println("total size = " + totalSize);
		return totalSize;
	}
	
}// end of class