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

Last change on this file since 2233 was 2233, checked in by pharms, 7 years ago
  • solved some findbugs issues
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.util.List;
19
20import de.ugoe.cs.util.console.Command;
21import de.ugoe.cs.util.console.Console;
22import de.ugoe.cs.util.console.GlobalDataContainer;
23
24/**
25 * <p>
26 * Command that lists the content of a directory {@link GlobalDataContainer}.
27 * </p>
28 *
29 * @author Ralph Krimmel
30 * @version 1.0
31 */
32public class CMDls implements Command {
33
34        /*
35         * (non-Javadoc)
36         *
37         * @see de.ugoe.cs.util.console.Command#run(java.util.List)
38         */
39        @Override
40        public void run(List<Object> parameters) {
41
42                String path;
43
44                if (parameters.isEmpty()) {
45                        path = ".";
46                } else {
47                        path = (String) parameters.get(0);
48                }
49
50                File dir = new File(path);
51                if (dir.isDirectory()) {
52                       
53                        File[] filesList = dir.listFiles();
54                        if (filesList != null) {
55                                for (File file : filesList) {
56                                        if (file.isFile()) {
57                                                Console.println("       " + file.getName());
58                                        } else {
59                                                if (file.isDirectory()) {
60                                                        Console.println("(d) " + file.getName());
61                                                }
62                                        }
63                                }
64                        }
65                }
66        }
67               
68        /*
69         * (non-Javadoc)
70         *
71         * @see de.ugoe.cs.util.console.Command#help()
72         */
73        @Override
74        public String help() {
75                return "ls <directory>";
76        }
77
78}
Note: See TracBrowser for help on using the repository browser.