1   // joi/10/juno/ListCommand.java                         
2   //                                                            
3   //                                                            
4   // Copyright 2003, Bill Campbell and Ethan Bolker                         
5                                                               
6   import java.util.*;
7   
8   /**
9    * The Juno shell command to list contents of the current directory.
10   * Usage:
11   * <pre>
12   *     list
13   * </pre>
14   *
15   * @version 10
16   */
17  
18  public class ListCommand extends ShellCommand 
19  {
20      // The constructor adds this object to the global table.
21  
22      ListCommand() 
23      {
24          super( "list contents of current directory" );
25      }
26  
27      /**
28       * List contents of the current working directory.
29       *
30       * @param args the remainder of the command line.
31       * @param sh   the current shell
32       *
33       * @exception JunoException for reporting errors
34       */
35  
36      public void doIt( StringTokenizer args, Shell sh )
37          throws JunoException 
38      {
39          OutputInterface terminal = sh.getConsole();
40          Directory dir            = sh.getDot();
41          String[] fileNames       = dir.getFileNames();
42  
43          terminal.println( dir.getPathName() );
44          for ( int i = 0; i < fileNames.length; i++ ) {
45              String fileName = fileNames[i];
46              JFile  jfile    = dir.retrieveJFile( fileName );
47              terminal.println( jfile.toString() ); 
48          }
49      }
50  }
51