public void rename(String frompath, String topath) throws PhileNotFoundException, FileSystemException { File oldname = new File(currentPath + "\\" + frompath); boolean newname = oldname.renameTo(new File(currentPath + "\\" + topath)); if (!newname) { throw new FileSystemException(currentPath + "\\" + topath); } takePath(); }
// formateaza un disk public void format() { File root = new File(currentDiskPath); File[] listOfFiles = root.listFiles(); for (int i = 0; i < listOfFiles.length; i++) { delete(listOfFiles[i]); } System.out.println("Format succesfull!"); takePath(); }
public void ls() { // OVERLOADING :(((( File folder = new File(currentPath); File[] listOfFiles = folder.listFiles(); for (int i = 0; i < listOfFiles.length; i++) { if (listOfFiles[i].isFile()) { System.out.println("File: " + listOfFiles[i].getName()); } else if (listOfFiles[i].isDirectory()) { System.out.println("Directory: " + listOfFiles[i].getName()); } } takePath(); }
public void mkdir(String newDirectoryName) { try { File newDirectory = new File(currentPath + "\\" + newDirectoryName); if (newDirectory.exists()) { System.out.println("Unable to create " + newDirectory.getAbsolutePath()); } else { newDirectory.mkdir(); System.out.println("Directory" + newDirectoryName + "created"); } } finally { takePath(); } }
// schimba directorul curent public void chdir(String path) { try { File currentDirectory = new File(currentPath); String[] allDirectories = currentDirectory.list(); boolean directoryExist = false; for (String item : allDirectories) { if (item.equals(path)) { directoryExist = true; } } if (directoryExist == true) currentPath = currentPath + "\\" + path; else System.out.println("The directory doesn't exists"); } finally { takePath(); } }
// deschide fereastra editorului pentru fisierul openPhilePath public void edit(String entry) throws PhileNotOpenException { try { String targetPath = currentPath + "\\" + entry; File file = new File(targetPath); if (!file.exists()) { System.out.println("Fisierul nu exista"); return; } Desktop dk = Desktop.getDesktop(); // Open a file dk.edit(file); } catch (Exception e) { } finally { takePath(); } }
// creaza si deschide fisierul cu numele specificat public void mkfile(String fileName) { try { File newFile = new File(currentPath + "\\" + fileName); if (newFile.exists()) { System.out.println("Unable to create " + newFile.getAbsolutePath()); } else { newFile.createNewFile(); System.out.println("Directory" + fileName + "created"); openFile(fileName); } } catch (Exception e) { e.printStackTrace(); } finally { takePath(); } }
// creaza un nou disk si un nou sistem de fisiere pe acesta public void newDisk(String diskName) { try { File newDisk = new File(System.getProperty("user.dir").toString() + "/" + diskName); if (newDisk.exists()) { System.out.println("Unable to create " + newDisk.getAbsolutePath()); } else { newDisk.mkdirs(); System.out.println("New disk created:" + diskName); addDiskRefernce(diskName); currentDiskPath = System.getProperty("user.dir").toString() + "\\" + diskName; currentPath = currentDiskPath; } } finally { takePath(); } }
// returneaza true daca entry reprezinta un director si false in caz contrar public boolean isDirectory(String entry) { try { String targetPath = currentPath + "\\" + entry; File file = new File(targetPath); if (!file.exists()) System.out.println("Fisierul nu exista"); if (file.isDirectory()) { System.out.println(entry + " este un director"); return true; } else { System.out.println(entry + " nu este un director"); return false; } } catch (Exception e) { return false; } finally { takePath(); } }
public static void delete(File file) { if (file.isFile()) file.delete(); File[] files = file.listFiles(); if (files != null) { // some JVMs return null for empty dirs for (File f : files) { if (f.isDirectory()) { delete(f); } else { f.delete(); } } } file.delete(); }
// copiaza frompath la topath public void move(String frompath, String topath) throws PhileNotFoundException { File from = new File(currentDiskPath + "\\" + frompath); String fullFromPath = from.getAbsolutePath(); String fileName = fullFromPath.substring(fullFromPath.lastIndexOf("\\"), fullFromPath.length()); File to = new File(currentDiskPath + "\\" + topath + fileName); if (from.exists() && to.getParentFile().isDirectory()) { from.renameTo(to); } else { System.out.println("Nu exista calea indicata"); } takePath(); }
// sterge un fisier/director cu numele name public void delete(String name) throws PhileNotFoundException { File targetFile = new File(currentPath + "\\" + name); if (targetFile.exists()) delete(targetFile); takePath(); }