Guest User

Untitled

a guest
Jan 21st, 2018
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.86 KB | None | 0 0
  1. /*************************************fileManager.java*************************************/
  2.  
  3. package file_manager;
  4. import java.io.*;
  5.  
  6. public class fileManager {
  7.    
  8.     public static void main (String[] args) {
  9.         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  10.         superCmd cmd = new superCmd();
  11.         String temp = null;
  12.        
  13.         do {
  14.             try { temp = br.readLine(); }
  15.             catch (IOException e) { System.out.println("Olvasási hiba!"); }
  16.            
  17.         } while (cmd.doCmd(temp) == 1);
  18.     }
  19. }
  20.  
  21. /***************************************superCmd.java**************************************/
  22.  
  23. package file_manager;
  24. import java.io.*;
  25.  
  26. public class superCmd {
  27.     private File dir;
  28.    
  29.     public superCmd () {
  30.         dir = new File (".");
  31.     }
  32.    
  33. /*********************************************Listing*********************************************/    
  34.    
  35.     public void ls (String[] args) {
  36.         File[] temp = dir.listFiles();
  37.        
  38.         for (int i=0; i<temp.length; i++) {
  39.             if (args.length==1 || !args[1].equals("-l")) {
  40.                 System.out.println(temp[i].getName());
  41.                 continue;
  42.             }
  43.            
  44.             if (temp[i].isDirectory()==true) {
  45.                 System.out.println("d " + temp[i].getName());
  46.             }
  47.             else {
  48.                 System.out.println("f " + temp[i].getName() + "\t" + temp[i].length() + " bájt");
  49.             }
  50.         }
  51.     }
  52.    
  53. /********************************************ChangeDir********************************************/
  54.    
  55.     public void cd (String[] args) {
  56.         System.out.println("cd");
  57.        
  58.         if (args.length<2) {
  59.             return;
  60.         }
  61.         if (args[1]=="..") {
  62.             dir=dir.getParentFile();
  63.         }
  64.         else {
  65.             try {
  66.                 dir = new File (dir.getCanonicalFile() + File.separator + args[1]);
  67.             } catch (IOException e) {
  68.                 System.out.println ("Nem létező könyvtár!");
  69.             }
  70.         }
  71.     }
  72.    
  73. /*********************************************MakeDir*********************************************/    
  74.    
  75.     public void mkdir (String [] args) {
  76.         if (args.length<2) {
  77.             return;
  78.         }
  79.        
  80.         try {
  81.             System.out.println (dir.getCanonicalPath() + File.separator + args[1]);
  82.             new File (dir.getCanonicalFile() + File.separator + args[1]).mkdir();
  83.         } catch (IOException e) {
  84.             System.out.println ("Már létezik a fájl!");
  85.         }
  86.     }
  87.    
  88. /*****************************************PrintWorkingDir*****************************************/
  89.    
  90.     public void pwd () {
  91.         try {
  92.             System.out.println (dir.getCanonicalPath());
  93.         } catch (IOException e) {}
  94.     }
  95.    
  96. /*********************************************Handler*********************************************/
  97.    
  98.     public int doCmd (String arg) {
  99.         String[] cmd = arg.split(" ");
  100.        
  101.              if (cmd[0].equals("ls")==true) ls(cmd);
  102.         else if (cmd[0].equals("cd")==true) cd(cmd);
  103.         else if (cmd[0].equals("mkdir")==true) mkdir(cmd);
  104.         else if (cmd[0].equals("pwd")==true) pwd();
  105.         else if (cmd[0].equals("exit")==true) return 0;
  106.         else System.out.println("Hibás parancs!");
  107.        
  108.         return 1;
  109.     }
  110. }
Add Comment
Please, Sign In to add comment