Example usage for java.io File list

List of usage examples for java.io File list

Introduction

In this page you can find the example usage for java.io File list.

Prototype

public String[] list(FilenameFilter filter) 

Source Link

Document

Returns an array of strings naming the files and directories in the directory denoted by this abstract pathname that satisfy the specified filter.

Usage

From source file:com.hp.test.framework.Utlis.java

public static int getLastRun(String path) {
    File file = new File(path + "\\results\\");
    String[] directories = file.list(new FilenameFilter() {
        @Override//from w w  w.  j  av a2 s  .  c  o m
        public boolean accept(File current, String name) {
            return new File(current, name).isDirectory();
        }
    });

    String temp_ar[] = directories[0].split("_");
    int max = Integer.parseInt(temp_ar[1]);
    for (int i = 1; i < directories.length; i++) {
        String temp_ar1[] = directories[i].split("_");

        int run = Integer.parseInt(temp_ar1[1]);

        if (run > max) {
            max = run;
        }

    }
    System.out.println(Arrays.toString(directories));
    System.out.println("Latest Run" + max);
    return max;
}

From source file:es.emergya.consultas.FlotaConsultas.java

public static List<String> getAllIcons(String dir) {
    List<String> res = new ArrayList<String>();
    try {/* w  w w. ja v  a 2s  .c  om*/
        URL u = FlotaConsultas.class.getResource(dir);
        if (u != null) {
            File f = new File(u.getFile());
            if (f.isDirectory()) {
                FilenameFilter filter = new FilenameFilter() {
                    public boolean accept(File dir, String name) {
                        return name.endsWith("_preview.png");
                    }
                };
                for (String path : f.list(filter))
                    res.add(path.substring(0, path.indexOf("_flota_preview")));
            }
        }
    } catch (Throwable t1) {
        log.error(t1, t1);
    }

    return res;
}

From source file:com.abiquo.am.services.filesystem.TemplateFileSystem.java

public static void deleteTemplate(final String packagePath) {
    File packageFile = new File(packagePath);
    String[] bundles = packageFile.list(new BundleImageFileFilter());
    if (bundles == null || bundles.length == 0) {
        LOG.debug("There are any bundle, deleting all the folder");
        try {/*from   w  w w.j  a v  a  2s  . c om*/
            FileUtils.deleteDirectory(packageFile);
        } catch (IOException e) {
            // caused by .nfs temp files (try retry in 5s)
            if (e instanceof FileNotFoundException) {
                try {
                    Thread.sleep(5000);
                } catch (InterruptedException e1) {
                    e1.printStackTrace();
                }

                try {
                    FileUtils.deleteDirectory(packageFile);
                } catch (IOException e1) {
                    throw new AMException(AMError.TEMPLATE_DELETE, packageFile.getAbsolutePath(), e1);
                }
            } // nfs issue

        }
        return;
    } else {
        final StringBuffer stBuffer = new StringBuffer();
        stBuffer.append("The selected Template has snapshot instances associates:");
        for (String bund : bundles) {
            stBuffer.append("\n" + bund);
        }

        stBuffer.append("\n It can not be deleted.");

        throw new AMException(AMError.TEMPLATE_DELETE_INSTANCES, stBuffer.toString());
    }
}

From source file:fr.paris.lutece.portal.service.spring.SpringContextService.java

/**
 * Initialize a global Application Context containing all beans (core + plugins)
 * Now uses GenericApplicationContext for better performances. A wrong formatted file
 * will not block block context to be built (without the file), but a wrong bean (i.e. cannot
 * be instantiated) will cause a full context failure. Context is less "failure-friendly"
 * @param servletContext The servlet context
 * @throws LuteceInitException The lutece init exception
 * @since 2.4/*w ww.j  ava  2  s  .c  om*/
 */
public static void init(ServletContext servletContext) throws LuteceInitException {
    try {
        // Register this service as a PluginEventListener
        PluginService.registerPluginEventListener(_instance);

        // timing
        Date dateBegin = new Date();

        // Load the core context file : core_context.xml
        String strConfPath = AppPathService.getAbsolutePathFromRelativePath(PATH_CONF);
        String strContextFile = "file:" + strConfPath + FILE_CORE_CONTEXT;

        GenericWebApplicationContext gwac = new GenericWebApplicationContext(servletContext);
        gwac.setId(getContextName(servletContext));

        XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(gwac);
        xmlReader.loadBeanDefinitions(strContextFile);

        // _context = new ClassPathXmlApplicationContext( strContextFile );
        AppLogService.info("Context file loaded : " + FILE_CORE_CONTEXT);

        // Load all context files found in the conf/plugins directory
        // Files are loaded separatly with an individual try/catch block
        // to avoid stopping the process in case of a failure
        // The global context generation will fail if a bean in any file cannot be built.
        String strConfPluginsPath = strConfPath + DIR_PLUGINS;
        File dirConfPlugins = new File(strConfPluginsPath);
        FilenameFilter filterContext = new ContextFileFilter();
        String[] filesContext = dirConfPlugins.list(filterContext);

        loadContexts(filesContext, strConfPluginsPath, xmlReader);

        // we now load overriding beans
        AppLogService.info("Loading plugins context overrides");

        String strCoreContextOverrideFile = strConfPath + DIR_OVERRIDE + FILE_CORE_CONTEXT;
        File fileCoreContextOverride = new File(strCoreContextOverrideFile);

        if (fileCoreContextOverride.exists()) {
            AppLogService.debug("Context file loaded : core_context");
            xmlReader.loadBeanDefinitions("file:" + strCoreContextOverrideFile);
        } else {
            AppLogService.debug("No core_context override found");
        }

        // load plugins overrides
        String strConfPluginsOverridePath = strConfPath + DIR_OVERRIDE_PLUGINS;
        File dirConfOverridePlugins = new File(strConfPluginsOverridePath);

        if (dirConfOverridePlugins.exists()) {
            String[] filesOverrideContext = dirConfOverridePlugins.list(filterContext);
            loadContexts(filesOverrideContext, strConfPluginsOverridePath, xmlReader);
        }

        gwac.refresh();

        _context = gwac;

        AppLogService.info("Spring context loaded in " + (new Date().getTime() - dateBegin.getTime()) + "ms");
    } catch (Exception e) {
        AppLogService.error("Error initializing Spring Context Service " + e.getMessage(), e);
        throw new LuteceInitException("Error initializing Spring Context Service", e);
    }
}

From source file:com.abiquo.am.services.filesystem.TemplateFileSystem.java

public static TemplateStateDto getTemplateStatus(final String enterpriseRepositoryPath, final String ovfId) {
    final TemplateStateDto state = new TemplateStateDto();
    state.setOvfId(ovfId);/*from  w  w  w  . j a v  a 2  s . c  o  m*/

    if (!TemplateConventions.isValidOVFLocation(ovfId)) {
        state.setStatus(TemplateStatusEnumType.ERROR);
        state.setErrorCause(AMError.TEMPLATE_INVALID_LOCATION.toString());
        return state;
    }

    final boolean isInstance = TemplateConventions.isBundleOvfId(ovfId);
    final String packagePath = getTemplatePath(enterpriseRepositoryPath, ovfId);

    if (isInstance) {

        final String snapshot = ovfId.substring(ovfId.lastIndexOf('/') + 1, ovfId.indexOf("-snapshot-"));
        final String masterPath = TemplateConventions.getTemplatePath(enterpriseRepositoryPath,
                TemplateConventions.getBundleMasterOvfId(ovfId));

        final File folder = new File(masterPath);
        if (folder.list(new FilenameFilter() {
            @Override
            public boolean accept(final File file, final String name) {
                return name.startsWith(snapshot);
            }

        }).length == 0) {
            state.setStatus(TemplateStatusEnumType.NOT_DOWNLOAD);
        } else {
            state.setStatus(TemplateStatusEnumType.DOWNLOAD);
        }

        return state;
    }

    final String ovfEnvelopePath = FilenameUtils.concat(enterpriseRepositoryPath,
            getRelativeTemplatePath(ovfId));

    File errorMarkFile = new File(packagePath + TEMPLATE_STATUS_ERROR_MARK);
    if (errorMarkFile.exists()) {
        state.setStatus(TemplateStatusEnumType.ERROR);
        state.setErrorCause(readErrorMarkFile(errorMarkFile));
    } else if (new File(packagePath + TEMPLATE_STATUS_DOWNLOADING_MARK).exists()) {
        state.setStatus(TemplateStatusEnumType.DOWNLOADING);

    } else if (!new File(ovfEnvelopePath).exists()) {
        state.setStatus(TemplateStatusEnumType.NOT_DOWNLOAD);
    } else {
        state.setStatus(TemplateStatusEnumType.DOWNLOAD);
    }

    return state;
}

From source file:net.sf.wickedshell.ui.shell.viewer.proposal.CompletionController.java

/**
 * Reads the systems's classpath and identifies all possible executable was
 * can currently be executed.//w  w w . j  av  a2s .  com
 * 
 * @return the <code>List</code> of <code>Completions</code> referring
 *         to the system path
 */
@SuppressWarnings("unchecked")
public static final List getSystemPathCompletions(IShellDescriptor descriptor) {
    Set systemPathCompletionSet = new HashSet();
    String systemPath = System.getProperty(ShellID.SYSTEM_PATH_KEY);
    String[] systemPathEntries = systemPath.split(String.valueOf(descriptor.getSystemPathSeparator()));
    File systemPathEntry;
    for (int systemPathEntryIndex = 0; systemPathEntryIndex < systemPathEntries.length; systemPathEntryIndex++) {
        systemPathEntry = new File(systemPathEntries[systemPathEntryIndex]);
        String[] completions = systemPathEntry.list(new ExecutableFileFilter(descriptor, false));
        if (completions != null) {
            for (int index = 0; index < completions.length; index++) {
                String completion = completions[index];
                String description = completions[index] + " - Execute <" + completions[index]
                        + "> (System path)";
                String imagePath = "img/systemPathExecutable.gif";
                systemPathCompletionSet
                        .add(ICompletion.Factory.newInstance(completion, description, imagePath));
            }
        }
    }
    List systemPathCompletions = new ArrayList(systemPathCompletionSet);
    Collections.sort(systemPathCompletions, new CompletionComparator());
    return systemPathCompletions;
}

From source file:com.meltmedia.cadmium.core.FileSystemManager.java

public static String[] getDirectoriesInDirectory(String directory, final String baseName) {
    File dir = new File(directory);
    if (dir.isDirectory()) {
        String files[] = null;//  w ww .  ja v  a 2  s  .c om
        files = dir.list(new FilenameFilter() {

            @Override
            public boolean accept(File file, String name) {
                if (baseName != null && baseName.length() > 0) {
                    return file.isDirectory() && file.isAbsolute() && name.startsWith(baseName);
                }
                return file.isDirectory();
            }

        });
        if (files != null) {
            return files;
        }
    }
    return new String[] {};
}

From source file:es.eucm.eadandroid.homeapp.repository.resourceHandler.RepoResourceHandler.java

/**
 * Gets the list of saved games from its folder
 *//*from w w w . ja  v a  2  s. c  o m*/
public static LoadGamesArray getexpandablelist() {

    LoadGamesArray info = new LoadGamesArray();

    String[] games = null;
    Bitmap[] screen_shots = null;

    if (!new File(Paths.eaddirectory.SAVED_GAMES_PATH).exists()) {

        new File(Paths.eaddirectory.SAVED_GAMES_PATH).mkdir();

    } else {

        File gamesfolders = new File(Paths.eaddirectory.SAVED_GAMES_PATH);
        games = gamesfolders.list(new EADFileFilter());

        if (games.length > 0) {

            for (int i = 0; i < games.length; i++) {

                File gamefolder = new File(Paths.eaddirectory.SAVED_GAMES_PATH + games[i] + "/");

                String files[] = gamefolder.list(new TxtFilter());

                String screen_shots_bitmaps[] = gamefolder.list(new PNGFilter());

                screen_shots = new Bitmap[files.length];

                for (int j = 0; j < files.length; j++) {

                    if (screen_shots_bitmaps.length > j && screen_shots_bitmaps[j] != null) {

                        Log.e("Path", screen_shots_bitmaps[j]);

                        screen_shots[j] = BitmapFactory.decodeFile(
                                Paths.eaddirectory.SAVED_GAMES_PATH + games[i] + "/" + screen_shots_bitmaps[j],
                                null);

                    }

                    info.addGame(games[i], files[j], screen_shots[j]);

                }

            }
        }
    }

    return info;
}

From source file:com.openteach.diamond.container.Container.java

private static void buildBundlesString(String parent, String child, StringBuilder sb, boolean first) {
    File file = new File(parent, child);
    if (file.exists()) {
        String filePath = file.getAbsolutePath();
        String[] pluginFiles = file.list(new FilenameFilter() {

            public boolean accept(File dir, String name) {
                if (name.endsWith(".plugin")) {
                    return true;
                }/*from www .ja v  a  2  s  .co  m*/
                return false;
            }
        });
        StringBuilder osgiBundlesBuilder = new StringBuilder();
        int pluginFilesSize = pluginFiles.length;
        if (pluginFilesSize > 0) {
            osgiBundlesBuilder.append(filePath + File.separator + pluginFiles[0]);
            osgiBundlesBuilder.append("@start");
        }
        for (int i = 1; i < pluginFilesSize; i++) {
            osgiBundlesBuilder.append(",");
            osgiBundlesBuilder.append(filePath + File.separator + pluginFiles[i]);
            osgiBundlesBuilder.append("@start");
        }
        if (first) {
            sb.append(osgiBundlesBuilder.toString());
        } else {
            sb.append("," + osgiBundlesBuilder.toString());
        }
    } else {
        if (first) {
            throw new RuntimeException("diamond???  "
                    + parent + " ??" + child + "!");
        }
    }
}

From source file:com.rukiasoft.androidapps.comunioelpuntal.crashlogs.ExceptionHandler.java

public static String[] searchForStackTraces() {
    if (stackTraceFileList != null) {
        return stackTraceFileList;
    }//from   ww w  .j  a v a  2  s  .  c  o  m
    File dir = new File(G.FILES_PATH + "/");
    // Try to create the files folder if it doesn't exist
    dir.mkdir();
    // Filter for ".stacktrace" files
    FilenameFilter filter = new FilenameFilter() {
        public boolean accept(File dir, String name) {
            return name.endsWith(".stacktrace");
        }
    };
    return (stackTraceFileList = dir.list(filter));
}