01: package org.mvel.sh.command.file;
02:
03: import org.mvel.sh.Command;
04: import org.mvel.sh.CommandException;
05: import org.mvel.sh.ShellSession;
06:
07: import java.io.File;
08:
09: public class DirList implements Command {
10: public Object execute(ShellSession session, String[] args) {
11: File current = new File(session.getEnv().get("$CWD"));
12:
13: if (!current.isDirectory())
14: throw new CommandException("cannot list directory : "
15: + session.getEnv().get("$CWD")
16: + " is not a directory");
17:
18: File[] files = current.listFiles();
19:
20: if (files.length == 0)
21: return null;
22: else {
23: System.out.append("Total ").append(
24: String.valueOf(files.length)).append("\n");
25: }
26:
27: for (File file : current.listFiles()) {
28: if (file.isDirectory()) {
29: System.out.append(file.getName()).append("/");
30: } else {
31: System.out.append(file.getName());
32: }
33: System.out.append("\n");
34: }
35: System.out.flush();
36:
37: return null;
38: }
39:
40: public String getDescription() {
41: return "performs a list of files and directories in the current working dir.";
42: }
43:
44: public String getHelp() {
45: return "no help yet";
46: }
47: }
|