//File: cd.java //CS 471 - Operating Systems Project //Dennis Pereira, Ely Soto, John Cavalieri import java.io.File; public class cd extends VMachine { /** Creates new cd */ public cd() { } public void run() { if(args.length == 1) // I there is only 1 argument which is expected properly change directories { String path = args[0]; try { File tfile; User curuser = sysapi.findUser(owner); if(args[0].trim().compareTo("..")==0) // Test for ".." and return to parent directory if found { tfile = new File(curuser.getcurrentPath()); tfile = new File(tfile.getParent()); if(tfile.isDirectory()) { curuser.setcurrentPath(tfile.getPath() + "\\"); } else { sysapi.Write(OUT,"Path is not a directory.\n"); } } else if (args[0].trim().compareTo(".")==0) { } else { tfile = new File(curuser.getcurrentPath() + path + "\\"); // Get current path and add the arguments path if(tfile.isDirectory()) { curuser.setcurrentPath(tfile.getPath() + "\\"); // Set the path. } else { sysapi.Write(OUT,"Path is not a directory.\n"); // Error statement if argument is not a directory } } } catch(Exception ex) { try { sysapi.Write(OUT,"Path not Found.\n"); } catch(Exception ex1) { System.out.println(ex1); } } } else if(args.length == 0) { try { sysapi.Write(OUT,"No path provided.\n"); // Error for having no arguments } catch(Exception ex1) { System.out.println(ex1); } } else { try { sysapi.Write(OUT,"Too many arguments.\n"); // Error for having to many arguments } catch(Exception ex1) { System.out.println(ex1); } } sysapi.Exit(vmh,owner); } }