private void ListSubDirectorySizes(File file) { File[] files; files = file.listFiles( new FileFilter() { @Override public boolean accept(File file) { // if (!file.isDirectory()){ // return false; //To change body of implemented methods use // File | Settings | File Templates. // }else{ // return true; // } return true; } }); Map<String, Long> dirListing = new HashMap<String, Long>(); for (File dir : files) { DiskUsage diskUsage = new DiskUsage(); diskUsage.accept(dir); // long size = diskUsage.getSize() / (1024 * 1024); long size = diskUsage.getSize(); dirListing.put(dir.getName(), size); } ValueComparator bvc = new ValueComparator(dirListing); TreeMap<String, Long> sorted_map = new TreeMap<String, Long>(bvc); sorted_map.putAll(dirListing); PrettyPrint(file, sorted_map); }
public static boolean deleteAll(File file) { boolean b = true; if ((file != null) && file.exists()) { if (file.isDirectory()) { try { File[] files = file.listFiles(); for (File f : files) b &= deleteAll(f); } catch (Exception e) { return false; } } b &= file.delete(); } return b; }
private void populateList() { try { String path = "."; fileList.setText(" "); String files; File folder = new File(path); File[] listOfFiles = folder.listFiles(); for (int i = 0; i < listOfFiles.length; i++) { if (listOfFiles[i].isFile()) { files = listOfFiles[i].getName(); // if(files.endsWith(".dat")) fileList.append(files + "\n"); } } } catch (java.security.AccessControlException k) { } }
boolean tryDir(String d) { ClassLoader L = getClass().getClassLoader(); File p = new File(d, PACKAGE); System.out.println("Try " + p); if (!p.exists() || !p.isDirectory()) return false; for (File f : p.listFiles()) { String s = f.getName(); if (!s.endsWith(".class")) continue; String name = s.substring(0, s.length() - 6); try { Class<?> c = L.loadClass(PACKAGE + "." + name); if (!Animator.class.isAssignableFrom(c)) continue; Animator a = (Animator) c.newInstance(); a.container().setPreferredSize(DIM); map.put(name, a); System.out.println(" " + name); // ClassNotFoundException InstantiationException IllegalAccessException } catch (Exception e) { continue; } } return map.size() > 0; }
public static boolean rmrf(File fi) { if (fi.isDirectory()) { boolean done = true; for (File subfi : fi.listFiles()) { if (!rmrf(subfi)) { done = false; } } if (!done) return false; return fi.delete(); } else { boolean done = true; for (int i = 0; i < 10; i++) { done = fi.delete(); if (done) break; try { Thread.sleep(100); } catch (InterruptedException e) { // do nothing } } return done; } }
private void cleanup(File directory) { // Clean up from old installations, removing or renaming files. // Note that directory is the parent of the CTP directory // unless the original installation was done by Bill Weadock's // all-in-one installer for Windows. // Get a file pointing to the CTP directory. // This might be the current directory, or // it might be the CTP child. File dir; if (directory.getName().equals("RSNA")) dir = directory; else dir = new File(directory, "CTP"); // If CTP.jar exists in this directory, it is a really // old CTP main file - not used anymore File ctp = new File(dir, "CTP.jar"); if (ctp.exists()) ctp.delete(); // These are old names for the Launcher.jar file File launcher = new File(dir, "CTP-launcher.jar"); if (launcher.exists()) launcher.delete(); launcher = new File(dir, "TFS-launcher.jar"); if (launcher.exists()) launcher.delete(); // Delete the obsolete CTP-runner.jar file File runner = new File(dir, "CTP-runner.jar"); if (runner.exists()) runner.delete(); // Delete the obsolete MIRC-copier.jar file File copier = new File(dir, "MIRC-copier.jar"); if (copier.exists()) copier.delete(); // Rename the old versions of the properties files File oldprops = new File(dir, "CTP-startup.properties"); File newprops = new File(dir, "CTP-launcher.properties"); File correctprops = new File(dir, "Launcher.properties"); if (oldprops.exists()) { if (newprops.exists() || correctprops.exists()) oldprops.delete(); else oldprops.renameTo(correctprops); } if (newprops.exists()) { if (correctprops.exists()) newprops.delete(); else newprops.renameTo(correctprops); } // Get rid of obsolete startup and shutdown programs File startup = new File(dir, "CTP-startup.jar"); if (startup.exists()) startup.delete(); File shutdown = new File(dir, "CTP-shutdown.jar"); if (shutdown.exists()) shutdown.delete(); // Get rid of the obsolete linux directory File linux = new File(dir, "linux"); if (linux.exists()) { startup = new File(linux, "CTP-startup.jar"); if (startup.exists()) startup.delete(); shutdown = new File(linux, "CTP-shutdown.jar"); if (shutdown.exists()) shutdown.delete(); linux.delete(); } // clean up the libraries directory File libraries = new File(dir, "libraries"); if (libraries.exists()) { // remove obsolete versions of the slf4j libraries // and the dcm4che-imageio libraries File[] files = libraries.listFiles(); for (File file : files) { if (file.isFile()) { String name = file.getName(); if (name.startsWith("slf4j-") || name.startsWith("dcm4che-imageio-rle")) { file.delete(); } } } // remove the email subdirectory File email = new File(libraries, "email"); deleteAll(email); // remove the xml subdirectory File xml = new File(libraries, "xml"); deleteAll(xml); // remove the sftp subdirectory File sftp = new File(libraries, "sftp"); deleteAll(xml); // move edtftpj.jar to the ftp directory File edtftpj = new File(libraries, "edtftpj.jar"); if (edtftpj.exists()) { File ftp = new File(libraries, "ftp"); ftp.mkdirs(); File ftpedtftpj = new File(ftp, "edtftpj.jar"); edtftpj.renameTo(ftpedtftpj); } } // remove the obsolete xml library under dir File xml = new File(dir, "xml"); deleteAll(xml); // remove the dicom profiles so any // obsolete files will disappear File profiles = new File(dir, "profiles"); File dicom = new File(profiles, "dicom"); deleteAll(dicom); dicom.mkdirs(); // Remove the index.html file so it will be rebuilt from // example-index.html when the system next starts. File root = new File(dir, "ROOT"); if (root.exists()) { File index = new File(root, "index.html"); index.delete(); } }
private File getFile(File dir, String nameStart, String nameEnd) { File[] files = dir.listFiles(new NameFilter(nameStart, nameEnd)); if (files.length == 0) return null; return files[0]; }
public void secureImport() { JFileChooser imp = new JFileChooser(); imp.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); imp.setMultiSelectionEnabled(true); int ret = imp.showOpenDialog(frm); if (ret != JFileChooser.APPROVE_OPTION) { return; } File[] fis = imp.getSelectedFiles(); ArrayList<String> impJobs = new ArrayList<String>(); boolean dirs = false; for (File fi : fis) { if (fi.isDirectory()) { dirs = true; File lib = new File(fi, LIBRARY_NAME); if (lib.exists()) { try { Scanner sca = new Scanner(lib); while (sca.hasNextLine()) { String nm = sca.nextLine(); String date = sca.nextLine(); String tags = sca.nextLine(); File addr = new File(fi, nm); if (addr.exists() && !addr.isDirectory()) impJobs.add(impJob(addr, date, tags)); } sca.close(); } catch (IOException exc) { // add nothing? } } else { for (File cont : fi.listFiles()) if (!cont.isDirectory()) impJobs.add(impJob(cont, null, null)); } } else { impJobs.add(impJob(fi, null, null)); } } if (impJobs.size() > 1 || dirs) { // dont bother user if selected single file String shw = "Importing:"; if (impJobs.size() > 30) shw = null; int pcount = 0; for (String jb : impJobs) { String[] prts = jb.split(",", 4); // import jobs have 4 parts, import, name, date, tags if (shw != null) shw = shw + "\n - " + new File(prts[1]).getName(); if (!prts[3].equalsIgnoreCase(Storage.NEW_TAG)) { pcount++; if (shw != null) shw = shw + " []"; } } if (shw == null) shw = "importing "; else shw = shw + "\n"; shw = shw + impJobs.size() + "(" + pcount + ") files"; if (JOptionPane.showConfirmDialog(frm, shw, "Confirm Import", JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION) return; } synchronized (jobs) { for (String j : impJobs) { if (priorityExport) jobs.addLast(j); else jobs.addFirst(j); } } updateStatus(); }
public boolean accept(File file) { if (file.isFile()) size += file.length(); else file.listFiles(this); return false; }
public QSAdminGUI(QSAdminMain qsadminMain, JFrame parentFrame) { this.parentFrame = parentFrame; Container cp = this; qsadminMain.setGUI(this); cp.setLayout(new BorderLayout(5, 5)); headerPanel = new HeaderPanel(qsadminMain, parentFrame); mainCommandPanel = new MainCommandPanel(qsadminMain); cmdConsole = new CmdConsole(qsadminMain); propertiePanel = new PropertiePanel(qsadminMain); if (headerPanel == null || mainCommandPanel == null || cmdConsole == null || propertiePanel == null) { throw new RuntimeException("Loading of one of gui component failed."); } headerPanel.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5)); cp.add(headerPanel, BorderLayout.NORTH); JScrollPane propertieScrollPane = new JScrollPane(propertiePanel); // JScrollPane commandScrollPane = new JScrollPane(mainCommandPanel); JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, mainCommandPanel, cmdConsole); splitPane.setOneTouchExpandable(false); splitPane.setDividerLocation(250); // splitPane.setDividerLocation(0.70); tabbedPane = new JTabbedPane(JTabbedPane.TOP); tabbedPane.addTab("Main", ball, splitPane, "Main Commands"); tabbedPane.addTab("Get/Set", ball, propertieScrollPane, "Properties Panel"); QSAdminPluginConfig qsAdminPluginConfig = null; PluginPanel pluginPanel = null; // -- start of loadPlugins try { File xmlFile = null; ClassLoader classLoader = null; Class mainClass = null; File file = new File(pluginDir); File dirs[] = null; if (file.canRead()) dirs = file.listFiles(new DirFileList()); for (int i = 0; dirs != null && i < dirs.length; i++) { xmlFile = new File(dirs[i].getAbsolutePath() + File.separator + "plugin.xml"); if (xmlFile.canRead()) { qsAdminPluginConfig = PluginConfigReader.read(xmlFile); if (qsAdminPluginConfig.getActive().equals("yes") && qsAdminPluginConfig.getType().equals("javax.swing.JPanel")) { classLoader = ClassUtil.getClassLoaderFromJars(dirs[i].getAbsolutePath()); mainClass = classLoader.loadClass(qsAdminPluginConfig.getMainClass()); logger.fine("Got PluginMainClass " + mainClass); pluginPanel = (PluginPanel) mainClass.newInstance(); if (JPanel.class.isInstance(pluginPanel) == true) { logger.info("Loading plugin : " + qsAdminPluginConfig.getName()); pluginPanelMap.put("" + (2 + i), pluginPanel); plugins.add(pluginPanel); tabbedPane.addTab( qsAdminPluginConfig.getName(), ball, (JPanel) pluginPanel, qsAdminPluginConfig.getDesc()); pluginPanel.setQSAdminMain(qsadminMain); pluginPanel.init(); } } else { logger.info( "Plugin " + dirs[i] + " is disabled so skipping " + qsAdminPluginConfig.getActive() + ":" + qsAdminPluginConfig.getType()); } } else { logger.info("No plugin configuration found in " + xmlFile + " so skipping"); } } } catch (Exception e) { logger.warning("Error loading plugin : " + e); logger.fine("StackTrace:\n" + MyString.getStackTrace(e)); } // -- end of loadPlugins tabbedPane.addChangeListener( new ChangeListener() { int selected = -1; int oldSelected = -1; public void stateChanged(ChangeEvent e) { // if plugin selected = tabbedPane.getSelectedIndex(); if (selected >= 2) { ((PluginPanel) pluginPanelMap.get("" + selected)).activated(); } if (oldSelected >= 2) { ((PluginPanel) pluginPanelMap.get("" + oldSelected)).deactivated(); } oldSelected = selected; } }); // tabbedPane.setBorder(BorderFactory.createEmptyBorder(0,5,5,5)); cp.add(tabbedPane, BorderLayout.CENTER); buildMenu(); }