import java.io.*; import java.text.DateFormat; import java.util.Date; public class ls extends VMachine { public ls() { } public void run() { try { File fileObject; String bytelength; int dircount = 0; int filecount = 0; long totalbytecount = 0; if(args[0].length() == 0) { fileObject = new File(sysapi.findUser(owner).getcurrentPath()); } else { fileObject = new File(sysapi.findUser(owner).getcurrentPath() + args[0]); } File[] listing = fileObject.listFiles(); if(fileObject.isDirectory()) { for(int x = 0; x < listing.length; x++) { if(listing[x].isDirectory()) { dircount++; sysapi.Write(OUT,DateFormat.getTimeInstance().format(new Date(listing[x].lastModified())) + " " + DateFormat.getDateInstance().format(new Date(listing[x].lastModified())) + " [DIR] " + " " + listing[x].getName() + "\n"); } else if(listing[x].isFile()) { filecount++; totalbytecount += listing[x].length(); bytelength = new String().valueOf(listing[x].length()); for(int i=0;bytelength.length() < 6;i++) { bytelength = " " + bytelength; } sysapi.Write(OUT,DateFormat.getTimeInstance().format(new Date(listing[x].lastModified())) + " " + DateFormat.getDateInstance().format(new Date(listing[x].lastModified())) + " " + bytelength + " " + listing[x].getName() + "\n"); } } if(filecount > 0) { sysapi.Write(OUT,new String().valueOf(totalbytecount) + " Bytes in " + new String().valueOf(filecount) + " File(s)\n"); } if(dircount > 0) { sysapi.Write(OUT,new String().valueOf(dircount) + " Directories(s)\n"); } } else { sysapi.Write(OUT,"Error -- Directory does not exist.\n"); } sysapi.Exit(vmh,owner); } catch (Exception err) { System.out.println(err); } } }