Advertisement
canezzy

javaavavavava

Mar 9th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. package main;
  2.  
  3. import java.io.File;
  4. import java.util.Scanner;
  5.  
  6. public class Main {
  7.  
  8. public static void main(String[] args) {
  9.  
  10. Scanner sc = new Scanner(System.in);
  11. String komanda = "";
  12. File currentDir = new File(".");
  13.  
  14. while (!(komanda.equals("quit"))){
  15. System.out.println(currentDir.getAbsolutePath() + " >");
  16. komanda = sc.nextLine();
  17. switch (komanda) {
  18. case "dir":
  19.  
  20. File[] files = currentDir.listFiles();
  21. for (File f : files) {
  22. if (f.isFile()) {
  23. System.out.println(f.getName());
  24. }
  25. }
  26. break;
  27.  
  28. case "cd":
  29.  
  30.  
  31. System.out.println("CD command called.");
  32. System.out.println("Current directory changed from <" + currentDir.getAbsolutePath() + "> to <" + currentDir.getParent() + ">\n");
  33. currentDir = new File(currentDir.getAbsoluteFile().getParent());
  34. break;
  35.  
  36. default:
  37. System.out.println("Invalid command!\n");
  38. break;
  39. }
  40.  
  41.  
  42. }
  43. }
  44.  
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement