Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public String cd (String path){
- //checks whether the directory available or not then return it
- File file = new File(path);
- File fileSameDir = new File(Dd+path);
- if (path.equals( "...")){
- int counter = 0;
- int index = Dd.length();
- boolean found = false;
- for (int i = 0; i < Dd.length(); i++) {
- if ((Dd.charAt(i)=='\\' || Dd.charAt(i) == '/')){
- found = true;
- }
- else if (found){
- index = i-1;
- found = false;
- }
- }
- System.out.println("Directory changed to "+obj.printWarning(Dd.substring(0,index+1)));
- return Dd.substring(0,index+1);
- }
- if (path.toLowerCase().equals("desktop")){
- System.out.println("Directory changed to " + obj.printWarning("Desktop"));
- return (System.getProperty("user.home") + "\\Desktop"+"\\");
- }
- if (fileSameDir.exists()){
- System.out.println("Directory changed to " + obj.printWarning(path));
- return (Dd+path+'\\');
- } else if (file.exists()){
- System.out.println("Directory changed to " + obj.printWarning(path));
- return path+"\\";
- }else if (path.equals("~")){
- System.out.println("Directory changed to " + obj.printWarning(path));
- Dd = System.getProperty("user.home")+'\\';
- return System.getProperty("user.home")+'\\';
- }
- else{
- System.out.println(obj.printError("Path may not be available use -mkdir- command to create directory"));
- return Dd;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement