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(); } }
// 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(); } }
// 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(); }
// 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(); } }
// 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(); }