Example usage for java.io File getName

List of usage examples for java.io File getName

Introduction

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

Prototype

public String getName() 

Source Link

Document

Returns the name of the file or directory denoted by this abstract pathname.

Usage

From source file:com.wipro.ats.bdre.filemon.FileScan.java

public static void scanAndAddToQueue() {
    try {/*from  w  w w .  j  ava  2 s  . co  m*/
        String scanDir = FileMonRunnableMain.getMonitoredDirName();
        LOGGER.debug("Scanning directory: " + scanDir);
        File dir = new File(scanDir);
        if (!dir.exists()) {
            LOGGER.info("Created monitoring dir " + dir + " success=" + dir.mkdirs());
        }
        File arcDir = new File(scanDir + "/" + FileMonRunnableMain.ARCHIVE);
        if (!arcDir.exists()) {
            LOGGER.info("Created monitoring dir " + arcDir + " success=" + arcDir.mkdirs());
        }
        // Getting list of files recursively from directory except '_archive' directory
        Collection<File> listOfFiles = FileUtils.listFiles(dir,
                new RegexFileFilter(FileMonRunnableMain.getFilePattern()),
                new RegexFileFilter("^(?:(?!" + FileMonRunnableMain.ARCHIVE + ").)*$"));
        String fileName = "";
        FileCopyInfo fileCopyInfo = null;
        for (File file : listOfFiles) {
            fileName = file.getName();
            LOGGER.debug("Matched File Pattern by " + fileName);
            fileCopyInfo = new FileCopyInfo();
            fileCopyInfo.setFileName(fileName);
            fileCopyInfo.setSubProcessId(FileMonRunnableMain.getSubProcessId());
            fileCopyInfo.setServerId(Integer.toString(123461));
            fileCopyInfo.setSrcLocation(file.getAbsolutePath());
            fileCopyInfo.setDstLocation(file.getParent().replace(FileMonRunnableMain.getMonitoredDirName(),
                    FileMonRunnableMain.getHdfsUploadDir()));
            fileCopyInfo.setFileHash(DigestUtils.md5Hex(FileUtils.readFileToByteArray(file)));
            fileCopyInfo.setFileSize(file.length());
            fileCopyInfo.setTimeStamp(file.lastModified());
            FileMonitor.addToQueue(fileName, fileCopyInfo);
        }
    } catch (Exception err) {
        LOGGER.error("Error in scan directory ", err);
        throw new BDREException(err);
    }
}

From source file:com.lovejoy777sarootool.rootool.dialogs.UnpackDialog.java

public static DialogFragment instantiate(File file1) {
    file = file1;/* w w  w. jav a2 s  . c o  m*/
    ext = FilenameUtils.getExtension(file1.getName());
    return new UnpackDialog();
}

From source file:com.lixiaocong.util.VideoFileHelper.java

public static boolean moveFiles(List<File> files, String destPath) {
    File dir = new File(destPath);
    if (!dir.isDirectory())
        return false;

    boolean ret = true;
    for (File file : files) {
        if (!file.renameTo(new File(destPath + file.getName()))) {
            ret = false;//  www  . j  av a 2 s .  c om
            logger.error("move " + file.getName() + " error");
        }
    }
    return ret;
}

From source file:io.github.azige.mages.Util.java

static List<Plugin> loadPluginsFromDirectory(File dir) {
    List<Plugin> list = new LinkedList<>();
    File[] files = dir.listFiles(new FilenameFilter() {

        @Override//w  ww  .j  av a2s.c  o m
        public boolean accept(File dir, String name) {
            return name.endsWith(".groovy");
        }
    });
    if (files == null) {
        return list;
    }
    try {
        GroovyClassLoader loader = new GroovyClassLoader();
        loader.addClasspath(dir.getCanonicalPath());
        final int extLength = ".groovy".length();
        for (File f : files) {
            String name = f.getName();
            String script = FileUtils.readFileToString(f, "UTF-8");
            list.add(wrapPlugin(name.substring(0, name.length() - extLength),
                    loader.parseClass(script).newInstance()));
        }
    } catch (Exception ex) {
        throw new MagesException(ex);
    }
    return list;
}

From source file:biomesoplenty.common.config.ModConfiguration.java

private static void loadBiomes() {
    for (BiomeGenBase biome : BiomeGenBase.getBiomeGenArray()) {
        if (biome != null) {
            BiomeConfiguration biomeConfiguration = BiomeConfiguration.getInstance(biome);

            biomeConfiguration.update();

            BiomeConfigUtil.configureBiome(biome, biomeConfiguration);
        }/*from w w  w  . j  ava 2 s  . c  om*/
    }

    for (File file : BiomeConfigUtil.getBiomeConfigDirectory().listFiles()) {
        if (FilenameUtils.getExtension(file.getName()).equals("cfg")) {
            System.out.println("Found custom config: " + file.getName());
        }
    }
}

From source file:cat.ogasoft.protocolizer.processor.CompilerPhase.java

public static void processCompiler(RoundEnvironment roundEnv) throws CompilerException {
    try {//from   w ww  .j  a v  a 2 s .c  o  m
        String protocPath = "src" + File.separatorChar + "cat" + File.separatorChar + "ogasoft"
                + File.separatorChar + "protocolizer" + File.separatorChar + "protoc";

        DefaultExecutor de = new DefaultExecutor();
        for (Element element : roundEnv.getElementsAnnotatedWith(ProtoFileV2.Compiler.class)) {
            ProtoFileV2.Compiler compiler = element.getAnnotation(ProtoFileV2.Compiler.class);
            if (compiler.compile()) {
                String base = protocPath.replace('.', File.separatorChar);
                File dst = new File(base);
                if (!dst.exists() && !dst.mkdirs()) {
                    throw new Exception("Cann not be created directory " + dst.getAbsolutePath());
                }
                File rootDirectori = new File(base);
                //Compile all the files in compiler.protoFilePaths()
                FileFilter filter = new FileFilter() {
                    @Override
                    public boolean accept(File pathname) {
                        return pathname.getName().toLowerCase().endsWith(".proto");
                    }
                };
                for (File protoc : rootDirectori.listFiles(filter)) {
                    String target = base + File.separatorChar + protoc.getName();
                    LOG.info("\tCompiling " + target + "...");
                    CommandLine cmd = CommandLine.parse(compiler.command() + " --proto_path=" + protocPath + " "
                            + compiler.language().option + "=src " + target);
                    int result = de.execute(cmd);
                    if (result != 0) {
                        throw new CompilerException("HO ho... somthing went wrong, code: " + result);
                    }
                    LOG.info("\t" + target + " compiled");
                }
            }
        }
    } catch (Exception e) {
        //Any exception is a CompilerException.
        throw new CompilerException(e.getMessage());
    }
}

From source file:SimpleFileFilter.java

/**
 * Returns the extension for a file or null if there is none
 * @param f the input file//from  w  w w. ja  v  a 2 s.c  o m
 * @return the file extension, or null if none
 */
public static String getExtension(File f) {
    return (f != null ? getExtension(f.getName()) : null);
}

From source file:Main.java

public static boolean isSupportedVideoFormat(File file) {
    return isSupportedVideoFormat(file.getName());
}

From source file:com.dnielfe.manager.dialogs.UnpackDialog.java

public static DialogFragment instantiate(File file1) {
    file = file1;/* ww w . j av a  2  s.co  m*/
    ext = FilenameUtils.getExtension(file1.getName());

    final UnpackDialog dialog = new UnpackDialog();
    return dialog;
}

From source file:com.docudile.app.services.utils.FileHandler.java

private static ArrayList<String> getFilePaths(String folderPath) {
    ArrayList<String> filenames = new ArrayList<>();
    File folder = new File(folderPath);

    for (File filename : folder.listFiles()) {
        if (filename.isFile()) {
            filenames.add(filename.getName());
        }// w  w  w.j  a va2s.com
    }
    return filenames;
}