[1305] | 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 |
|
---|
| 15 | package de.ugoe.cs.autoquest.commands.misc;
|
---|
| 16 |
|
---|
| 17 | import java.io.File;
|
---|
| 18 | import java.util.List;
|
---|
| 19 |
|
---|
| 20 | import de.ugoe.cs.util.console.Command;
|
---|
| 21 | import de.ugoe.cs.util.console.Console;
|
---|
| 22 | import 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 | */
|
---|
| 32 | public 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 | for (File file : filesList) {
|
---|
| 55 | if (file.isFile()) {
|
---|
| 56 | Console.println(" " + file.getName());
|
---|
| 57 | } else {
|
---|
| 58 | if (file.isDirectory()) {
|
---|
| 59 | Console.println("(d) " + file.getName());
|
---|
| 60 | }
|
---|
| 61 | }
|
---|
| 62 | }
|
---|
| 63 | }
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | /*
|
---|
| 67 | * (non-Javadoc)
|
---|
| 68 | *
|
---|
| 69 | * @see de.ugoe.cs.util.console.Command#help()
|
---|
| 70 | */
|
---|
| 71 | @Override
|
---|
| 72 | public String help() {
|
---|
| 73 | return "ls <directory>";
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | }
|
---|