source: trunk/autoquest-ui-core/src/main/java/de/ugoe/cs/autoquest/commands/misc/CMDls.java @ 1305

Last change on this file since 1305 was 1305, checked in by rkrimmel, 11 years ago

Adding a ls like command to the Console

File size: 1.9 KB
Line 
1//   Copyright 2012 Georg-August-Universität Göttingen, Germany
2//
3//   Licensed under the Apache License, Version 2.0 (the "License");
4//   you may not use this file except in compliance with the License.
5//   You may obtain a copy of the License at
6//
7//       http://www.apache.org/licenses/LICENSE-2.0
8//
9//   Unless required by applicable law or agreed to in writing, software
10//   distributed under the License is distributed on an "AS IS" BASIS,
11//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12//   See the License for the specific language governing permissions and
13//   limitations under the License.
14
15package de.ugoe.cs.autoquest.commands.misc;
16
17import java.io.File;
18import java.io.FileInputStream;
19import java.io.IOException;
20import java.io.ObjectInputStream;
21import java.util.List;
22
23import de.ugoe.cs.util.console.Command;
24import de.ugoe.cs.util.console.Console;
25import de.ugoe.cs.util.console.GlobalDataContainer;
26
27/**
28 * <p>
29 * Command that lists the content of a directory {@link GlobalDataContainer}.
30 * </p>
31 *
32 * @author Ralph Krimmel
33 * @version 1.0
34 */
35public class CMDls implements Command {
36
37        /*
38         * (non-Javadoc)
39         *
40         * @see de.ugoe.cs.util.console.Command#run(java.util.List)
41         */
42        @Override
43        public void run(List<Object> parameters) {
44
45                String path;
46
47                if (parameters.isEmpty()) {
48                        path = ".";
49                } else {
50                        path = (String) parameters.get(0);
51                }
52
53                File dir = new File(path);
54                if (dir.isDirectory()) {
55                       
56                        File[] filesList = dir.listFiles();
57                        for (File file : filesList) {
58                                if (file.isFile()) {
59                                        Console.println("       " + file.getName());
60                                } else {
61                                        if (file.isDirectory()) {
62                                                Console.println("(d) " + file.getName());
63                                        }
64                                }
65                        }
66                }
67        }
68               
69        /*
70         * (non-Javadoc)
71         *
72         * @see de.ugoe.cs.util.console.Command#help()
73         */
74        @Override
75        public String help() {
76                return "ls <directory>";
77        }
78
79}
Note: See TracBrowser for help on using the repository browser.