Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main;
- import java.io.File;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- String komanda = "";
- File currentDir = new File(".");
- while (!(komanda.equals("quit"))){
- System.out.println(currentDir.getAbsolutePath() + " >");
- komanda = sc.nextLine();
- switch (komanda) {
- case "dir":
- File[] files = currentDir.listFiles();
- for (File f : files) {
- if (f.isFile()) {
- System.out.println(f.getName());
- }
- }
- break;
- case "cd":
- System.out.println("CD command called.");
- System.out.println("Current directory changed from <" + currentDir.getAbsolutePath() + "> to <" + currentDir.getParent() + ">\n");
- currentDir = new File(currentDir.getAbsoluteFile().getParent());
- break;
- default:
- System.out.println("Invalid command!\n");
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement