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() 

Source Link

Document

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

Usage

From source file:net.longfalcon.web.AdminIndexController.java

@RequestMapping(value = "/admin/site-edit", method = RequestMethod.GET)
public String editSiteView(Model model, HttpSession httpSession) {
    Site site = config.getDefaultSite();
    model.addAttribute("title", "Site Edit");
    model.addAttribute("siteObject", site);

    List<String> themeNameList = new ArrayList<>();
    try {//from   ww w  .  j  av a2 s .c om
        String realPath = httpSession.getServletContext().getRealPath("/public-resources/themes");
        File themesDir = new File(realPath);
        String[] themeDirList = themesDir.list();
        Collections.addAll(themeNameList, themeDirList);
    } catch (Exception e) {
        _log.error(e, e);
    }

    Map<Integer, String> showPasswordedRelOptionsMap = new HashMap<>();
    showPasswordedRelOptionsMap.put(0, "Dont show passworded or potentially passworded");
    showPasswordedRelOptionsMap.put(1, "Dont show passworded");
    showPasswordedRelOptionsMap.put(2, "Show everything");

    Map<Integer, String> newGroupsScanMethodMap = new HashMap<>();
    newGroupsScanMethodMap.put(1, "Days");
    newGroupsScanMethodMap.put(0, "Posts");

    Map<Integer, String> registerStatusMap = new HashMap<>();
    registerStatusMap.put(SiteService.REGISTER_STATUS_OPEN, "Open");
    registerStatusMap.put(SiteService.REGISTER_STATUS_INVITE, "Invite");
    registerStatusMap.put(SiteService.REGISTER_STATUS_CLOSED, "Closed");

    model.addAttribute("yesNoMap", YES_NO_MAP);
    model.addAttribute("showPasswordedRelOptionsMap", showPasswordedRelOptionsMap);
    model.addAttribute("newGroupsScanMethodMap", newGroupsScanMethodMap);
    model.addAttribute("registerStatusMap", registerStatusMap);
    model.addAttribute("themeNameList", themeNameList);
    return "admin/site-edit";
}

From source file:CreatingTreeModel.java

public int getChildCount(Object parent) {
    File fileSystemMember = (File) parent;
    if (fileSystemMember.isDirectory()) {
        String[] directoryMembers = fileSystemMember.list();
        return directoryMembers.length;
    }//from  www.ja v  a2s.  c  om

    else {

        return 0;
    }
}

From source file:com.beaconhill.yqd.DataDir.java

List<String> getSymbols(String directoryPath) {

    File dir = new File(directoryPath);

    String[] children = dir.list();

    // It is also possible to filter the list of returned files.
    // This example does not return any files that start with `.'.
    FilenameFilter filter = new FilenameFilter() {
        public boolean accept(File dir, String name) {
            String lname = name.toLowerCase();
            return lname.endsWith(".csv");
        }//from  ww w  . j ava2  s  . c  o  m
    };
    children = dir.list(filter);
    List<String> rtn = new ArrayList<String>();
    for (String s : children) {
        try {
            rtn.add(FilenameUtils.getBaseName((new File(s).getCanonicalPath()).toUpperCase()));
        } catch (IOException ioEx) {
            System.err.println(ioEx.getMessage());
        }
    }

    return rtn;
}

From source file:gdt.data.entity.ArchiveHandler.java

/**
 * Insert entities from the cache directory into the database. 
 * @param  entigrator entigrator instance
 * @param cache$ directory path/*from w ww.ja  v  a  2  s  .com*/
 * @param keep boolean value. 
 * If keep is true then keep existing entities. 
 * If keep is false then replace existing entities.  
 *  @return array of keys of inserted entities.
 */
public static String[] insertCache(Entigrator entigrator, String cache$, boolean keep) {
    try {
        File entityBodies = new File(cache$ + "/" + Entigrator.ENTITY_BASE + "/data/");
        String[] sa = entityBodies.list();
        Sack entity;
        File cacheEntityHome;
        File entityHome;
        for (String s : sa) {
            if (keep && entigrator.indx_getLabel(s) != null)
                continue;
            entity = Sack.parseXML(entityBodies.getPath() + "/" + s);

            if (entity != null)
                entigrator.save(entity);
            entigrator.ent_reindex(entity);
            cacheEntityHome = new File(cache$ + "/" + s);
            if (cacheEntityHome.exists()) {
                entityHome = new File(entigrator.ent_getHome(s));
                if (!entityHome.exists())
                    entityHome.mkdir();
                FileExpert.copyAll(cacheEntityHome.getPath(), entityHome.getPath());
            }
        }
        File cacheIcons = new File(cache$ + "/" + Entigrator.ICONS);
        if (cacheIcons.exists())
            if (!keep)
                FileExpert.copyAll(cacheIcons.getPath(), entigrator.getEntihome() + "/" + Entigrator.ICONS);
            else {

                String icons = entigrator.getEntihome() + "/" + Entigrator.ICONS;
                File[] fa = cacheIcons.listFiles();
                File icon;
                for (File f : fa) {
                    icon = new File(icons + "/" + f.getName());
                    if (icon.exists())
                        continue;
                    icon.createNewFile();
                    FileExpert.copyFile(f, icon);
                }
            }
        return sa;
    } catch (Exception e) {
        Logger.getLogger(ArchiveHandler.class.getName()).severe(e.toString());
    }
    return null;
}

From source file:hudson.plugins.doclinks.artifacts.testtools.TestZipBuilder.java

private void compress(ZipOutputStream zos, File dir, String relative) throws IOException {
    for (String filename : dir.list()) {
        File file = new File(dir, filename);
        String path = StringUtils.isEmpty(relative) ? filename : String.format("%s/%s", relative, filename);
        if (file.isDirectory()) {
            if (!noEntryForDirectories) {
                ZipEntry entry = new ZipEntry(String.format("%s/", path));
                zos.putNextEntry(entry);
            }//from  w ww.  ja v a 2s .  c  o  m
            compress(zos, file, path);
        } else {
            ZipEntry entry = new ZipEntry(path);
            zos.putNextEntry(entry);
            FileInputStream is = null;
            try {
                is = new FileInputStream(file);
                IOUtils.copy(is, zos);
            } finally {
                if (is != null) {
                    is.close();
                }
            }
        }
    }
}

From source file:eu.cloud4soa.soa.utils.SemanticAppInitializer.java

public void initialize() throws SOAException {

    try {//from   w w w.  ja  v  a 2s .co m
        String developerUserDir = "applicationProfiles";
        URL resource = scanPackage(developerUserDir);
        String protocol = resource.getProtocol();
        if (protocol.equals("file")) {
            File file = new File(resource.getFile());
            if (file.isDirectory()) {
                String[] list = file.list();
                for (String fileName : list) {
                    String applicationTurtleProfile = loadTurtleFileIntoString(developerUserDir, fileName);
                    logger.info("Loaded application profile: " + fileName);
                    storeTurtleApplicationProfile(applicationTurtleProfile, developerUriId);
                }
            }
        }
    } catch (IOException ex) {
        logger.error("Error during the creation of the Application profiles", ex);
    }
}

From source file:eu.scape_project.pc.droid.cli.DroidCli.java

private void processFiles(File path) throws FileNotFoundException, IOException {

    if (path.isDirectory()) {
        String[] children = path.list();
        for (int i = 0; i < children.length; i++) {
            processFiles(new File(path, children[i]));
        }/*  w  w  w.j a  v  a2 s  . c  o m*/
    } else {
        processFile(path);
    }
}

From source file:dao.CopyDirDao.java

public void copyDir(String src, String dest) {
    File source = new File(src);
    dest = dest + File.separator + source.getName();
    File destination = new File(dest);
    destination.mkdir();/*from   ww w.  j av  a2  s . c om*/
    String files[] = source.list();
    for (String file : files) {

        File srcFile = new File(src, file);
        File destFile = new File(dest, file);
        try {
            //recursive copy
            FileUtils.copyFile(srcFile, destFile);
        } catch (IOException ex) {
        }
    }

}

From source file:ch.sbb.releasetrain.config.ConfigAccessorImpl.java

@Override
public List<String> readAllConfigs() {
    List<String> ret = new ArrayList<>();
    File dir = git.getRepo().directory();
    for (String file : dir.list()) {
        if (file.contains("-type.yml")) {
            ret.add(file.replace("-type.yml", ""));
        }/*from   w  ww . j ava2s .  c  om*/
    }
    ret.remove("defaultConfig");
    return ret;
}

From source file:ch.sbb.releasetrain.config.ConfigAccessorImpl.java

public void deleteConfig(String name) {
    List<String> ret = new ArrayList<>();
    File dir = git.getRepo().directory();
    for (String file : dir.list()) {
        if (file.contains(name)) {
            try {
                FileUtils.forceDelete(new File(dir, file));
            } catch (IOException e) {
                log.error(e.getMessage(), e);
            }/*from   www . j av  a2s  .co m*/
        }
    }
}