Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. public String cd (String path){
  2. //checks whether the directory available or not then return it
  3.  
  4. File file = new File(path);
  5.  
  6. File fileSameDir = new File(Dd+path);
  7.  
  8. if (path.equals( "...")){
  9.  
  10. int counter = 0;
  11. int index = Dd.length();
  12. boolean found = false;
  13.  
  14. for (int i = 0; i < Dd.length(); i++) {
  15.  
  16. if ((Dd.charAt(i)=='\\' || Dd.charAt(i) == '/')){
  17. found = true;
  18. }
  19.  
  20. else if (found){
  21. index = i-1;
  22. found = false;
  23. }
  24.  
  25. }
  26. System.out.println("Directory changed to "+obj.printWarning(Dd.substring(0,index+1)));
  27. return Dd.substring(0,index+1);
  28. }
  29.  
  30. if (path.toLowerCase().equals("desktop")){
  31.  
  32. System.out.println("Directory changed to " + obj.printWarning("Desktop"));
  33.  
  34. return (System.getProperty("user.home") + "\\Desktop"+"\\");
  35. }
  36.  
  37. if (fileSameDir.exists()){
  38.  
  39. System.out.println("Directory changed to " + obj.printWarning(path));
  40.  
  41. return (Dd+path+'\\');
  42.  
  43. } else if (file.exists()){
  44.  
  45. System.out.println("Directory changed to " + obj.printWarning(path));
  46.  
  47. return path+"\\";
  48.  
  49. }else if (path.equals("~")){
  50.  
  51. System.out.println("Directory changed to " + obj.printWarning(path));
  52. Dd = System.getProperty("user.home")+'\\';
  53. return System.getProperty("user.home")+'\\';
  54. }
  55. else{
  56. System.out.println(obj.printError("Path may not be available use -mkdir- command to create directory"));
  57. return Dd;
  58. }
  59.  
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement