//File: mv.java //CS 471 - Operating Systems Project //Dennis Pereira, Ely Soto, John Cavalieri import java.io.*; import java.util.*; // This file moves a file to a certain directoy or renames the file if the directory doesn't exist. public class mv extends VMachine { public mv() { } public void run() { try { String currentFile = ""; // initialize variables String newFile = ""; File fileObject, newName; StringTokenizer tokens; boolean flagged = false; if(args.length < 2) // mv requires two arguments { sysapi.Write(OUT,"Error -- Not enough parameters\n"); flagged = true; } else if(args.length > 2) { sysapi.Write(OUT,"Error - Too many parameters\n"); } else { tokens = new StringTokenizer(args[0]); currentFile = args[0]; // set current file newFile = args[1]; // set new file } fileObject = new File(sysapi.findUser(owner).getcurrentPath() + currentFile); // Get current path and add file name newName = new File(sysapi.findUser(owner).getcurrentPath() + newFile); // Assign it its new name or directory if(newName.isDirectory()) // move the file to the new directory path { newName = new File(sysapi.findUser(owner).getcurrentPath() + newFile + "/" + currentFile); } if(fileObject.exists()) // If the directory is not found rename it and keep in same directory { fileObject.renameTo(newName); } else // Error statement if the file doesn't exist. { sysapi.Write(OUT, "Error -- File or directory does not exist.\n"); } sysapi.Exit(vmh,owner); } catch (Exception err) { System.out.println("mv threw an Exception.\n"); } } }