adammurdoch    2003/06/28 03:49:21

  Modified:    vfs/src/java/org/apache/commons/vfs/example Shell.java
  Log:
  Show some info when doing 'ls' on a file.
  
  Revision  Changes    Path
  1.3       +25 -9     
jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/example/Shell.java
  
  Index: Shell.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/example/Shell.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Shell.java        17 Mar 2003 09:07:55 -0000      1.2
  +++ Shell.java        28 Jun 2003 10:49:21 -0000      1.3
  @@ -58,15 +58,18 @@
   import java.io.BufferedReader;
   import java.io.IOException;
   import java.io.InputStreamReader;
  +import java.text.DateFormat;
   import java.util.ArrayList;
  +import java.util.Date;
   import java.util.StringTokenizer;
  +import org.apache.commons.vfs.FileContent;
   import org.apache.commons.vfs.FileObject;
   import org.apache.commons.vfs.FileSystemException;
   import org.apache.commons.vfs.FileSystemManager;
   import org.apache.commons.vfs.FileType;
   import org.apache.commons.vfs.FileUtil;
  -import org.apache.commons.vfs.VFS;
   import org.apache.commons.vfs.Selectors;
  +import org.apache.commons.vfs.VFS;
   
   /**
    * A simple command-line shell for performing file operations.
  @@ -181,7 +184,7 @@
           System.out.println( "cd [folder]        Changes current folder." );
           System.out.println( "cp <src> <dest>    Copies a file or folder." );
           System.out.println( "help               Shows this message." );
  -        System.out.println( "ls [-R] [folder]   Lists contents of a folder." );
  +        System.out.println( "ls [-R] [path]     Lists contents of a file or 
folder." );
           System.out.println( "pwd                Displays current folder." );
           System.out.println( "rm <path>          Deletes a file or folder." );
           System.out.println( "touch <path>       Sets the last-modified time of a 
file." );
  @@ -272,19 +275,32 @@
               recursive = false;
           }
   
  -        final FileObject dir;
  +        final FileObject file;
           if ( cmd.length > pos )
           {
  -            dir = mgr.resolveFile( cwd, cmd[ pos ] );
  +            file = mgr.resolveFile( cwd, cmd[ pos ] );
           }
           else
           {
  -            dir = cwd;
  +            file = cwd;
           }
   
  -        // List the contents
  -        System.out.println( "Contents of " + dir.getName() );
  -        listChildren( dir, recursive, "" );
  +        if ( file.getType() == FileType.FOLDER )
  +        {
  +            // List the contents
  +            System.out.println( "Contents of " + file.getName() );
  +            listChildren( file, recursive, "" );
  +        }
  +        else
  +        {
  +            // Stat the file
  +            System.out.println( file.getName() );
  +            final FileContent content = file.getContent();
  +            System.out.println( "Size: " + content.getSize() + " bytes." );
  +            final DateFormat dateFormat = DateFormat.getDateTimeInstance( 
DateFormat.MEDIUM, DateFormat.MEDIUM );
  +            final String lastMod = dateFormat.format( new Date( 
content.getLastModifiedTime() ) );
  +            System.out.println( "Last modified: " + lastMod );
  +        }
       }
   
       /** Does a 'touch' command. */
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to