1 package net.sf.tomp.xtcl.command;
2
3 import net.sf.tomp.xtcl.Context;
4
5 import java.io.File;
6
7 /***
8 * Changes the working (current) directory.
9 *
10 * @author tomp
11 */
12 public class Cd extends FileCommand {
13 /***
14 * Changes the working (current) directory.
15 *
16 * @param context is asked for the working directory,
17 * working dir is set to the new one.
18 * @return 0 (OK) if the dir exists, 1 otherwise
19 * @throws Exception DOCUMENT ME!
20 */
21 public int execute(Context context) throws Exception {
22 File newPath = context.getFile(fileName);
23
24 context.setRealPath(newPath);
25
26 boolean ok = newPath.exists();
27
28 return done(context, ok ? 0 : 1);
29 }
30
31 /***
32 * DOCUMENT ME!
33 *
34 * @return DOCUMENT ME!
35 */
36 public String toString() {
37 return "CHDIR " + fileName;
38 }
39 }
40
41 /*
42 * The contents of this file are subject to the Mozilla Public License Version
43 * 1.1 (the "License"); you may not use this file except in compliance with the
44 * License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
45 * Software distributed under the License is distributed on an "AS IS" basis,
46 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
47 * the specific language governing rights and limitations under the License. The
48 * Original Code is: all this file. The Initial Developer of the Original Code
49 * is: Tomas Pitner, Masaryk University in Brno, Czech Republic. Contributor(s):
50 */