You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by gg...@apache.org on 2003/11/28 18:27:16 UTC

cvs commit: jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/example Shell.java

ggregory    2003/11/28 09:27:16

  Modified:    vfs/src/java/org/apache/commons/vfs/example Shell.java
  Log:
  cd command now checks the validity of the target.
  
  Revision  Changes    Path
  1.5       +19 -14    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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Shell.java	13 Oct 2003 08:45:23 -0000	1.4
  +++ Shell.java	28 Nov 2003 17:27:16 -0000	1.5
  @@ -75,7 +75,8 @@
    * A simple command-line shell for performing file operations.
    *
    * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
  - * @version $Revision$ $Date$
  + * @author Gary D. Gregory
  + * @version $Id$
    */
   public class Shell
   {
  @@ -242,24 +243,28 @@
           System.out.println( "Current folder is " + cwd.getName() );
       }
   
  -    /** Does a 'cd' command. */
  -    private void cd( final String[] cmd ) throws Exception
  -    {
  +    /** 
  +     * Does a 'cd' command.
  +     * If the taget directory does not exist, a message is printed to <code>System.err</code>. 
  +     */
  +    private void cd(final String[] cmd) throws Exception {
           final String path;
  -        if ( cmd.length > 1 )
  -        {
  -            path = cmd[ 1 ];
  -        }
  -        else
  -        {
  -            path = System.getProperty( "user.home" );
  +        if (cmd.length > 1) {
  +            path = cmd[1];
  +        } else {
  +            path = System.getProperty("user.home");
           }
   
           // Locate and validate the folder
  -        cwd = mgr.resolveFile( cwd, path );
  -        System.out.println( "Current folder is " + cwd.getName() );
  +        FileObject tmp = mgr.resolveFile(cwd, path);
  +        if (tmp.exists()) {
  +            cwd = tmp;
  +        } else {
  +            System.out.println("Folder does not exist: " + tmp.getName());
  +        }
  +        System.out.println("Current folder is " + cwd.getName());
       }
  -
  +    
       /** Does an 'ls' command. */
       private void ls( final String[] cmd ) throws FileSystemException
       {
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org