Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*************************************fileManager.java*************************************/
- package file_manager;
- import java.io.*;
- public class fileManager {
- public static void main (String[] args) {
- BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
- superCmd cmd = new superCmd();
- String temp = null;
- do {
- try { temp = br.readLine(); }
- catch (IOException e) { System.out.println("Olvasási hiba!"); }
- } while (cmd.doCmd(temp) == 1);
- }
- }
- /***************************************superCmd.java**************************************/
- package file_manager;
- import java.io.*;
- public class superCmd {
- private File dir;
- public superCmd () {
- dir = new File (".");
- }
- /*********************************************Listing*********************************************/
- public void ls (String[] args) {
- File[] temp = dir.listFiles();
- for (int i=0; i<temp.length; i++) {
- if (args.length==1 || !args[1].equals("-l")) {
- System.out.println(temp[i].getName());
- continue;
- }
- if (temp[i].isDirectory()==true) {
- System.out.println("d " + temp[i].getName());
- }
- else {
- System.out.println("f " + temp[i].getName() + "\t" + temp[i].length() + " bájt");
- }
- }
- }
- /********************************************ChangeDir********************************************/
- public void cd (String[] args) {
- System.out.println("cd");
- if (args.length<2) {
- return;
- }
- if (args[1]=="..") {
- dir=dir.getParentFile();
- }
- else {
- try {
- dir = new File (dir.getCanonicalFile() + File.separator + args[1]);
- } catch (IOException e) {
- System.out.println ("Nem létező könyvtár!");
- }
- }
- }
- /*********************************************MakeDir*********************************************/
- public void mkdir (String [] args) {
- if (args.length<2) {
- return;
- }
- try {
- System.out.println (dir.getCanonicalPath() + File.separator + args[1]);
- new File (dir.getCanonicalFile() + File.separator + args[1]).mkdir();
- } catch (IOException e) {
- System.out.println ("Már létezik a fájl!");
- }
- }
- /*****************************************PrintWorkingDir*****************************************/
- public void pwd () {
- try {
- System.out.println (dir.getCanonicalPath());
- } catch (IOException e) {}
- }
- /*********************************************Handler*********************************************/
- public int doCmd (String arg) {
- String[] cmd = arg.split(" ");
- if (cmd[0].equals("ls")==true) ls(cmd);
- else if (cmd[0].equals("cd")==true) cd(cmd);
- else if (cmd[0].equals("mkdir")==true) mkdir(cmd);
- else if (cmd[0].equals("pwd")==true) pwd();
- else if (cmd[0].equals("exit")==true) return 0;
- else System.out.println("Hibás parancs!");
- return 1;
- }
- }
Add Comment
Please, Sign In to add comment