Example usage for java.nio.file FileVisitOption FOLLOW_LINKS

List of usage examples for java.nio.file FileVisitOption FOLLOW_LINKS

Introduction

In this page you can find the example usage for java.nio.file FileVisitOption FOLLOW_LINKS.

Prototype

FileVisitOption FOLLOW_LINKS

To view the source code for java.nio.file FileVisitOption FOLLOW_LINKS.

Click Source Link

Document

Follow symbolic links.

Usage

From source file:squash.deployment.lambdas.utils.FileUtils.java

/**
 * Adds revving suffix to all filenames beneath a folder.
 * /*from  ww  w.  j ava  2  s. c  o m*/
 * <p>Adds revving suffix to all filenames beneath a folder, recursing into subfolders.
 *    Only js and css files are revved.
 * 
 *    @param suffix the suffix to add to all filenames.
 *    @param startFolder the folder at root of tree within which to suffix files
 *    @param logger a CloudwatchLogs logger.
 * @throws IOException
 */
public static void appendRevvingSuffix(String suffix, Path startFolder, LambdaLogger logger)
        throws IOException {
    Files.walk(startFolder, FileVisitOption.FOLLOW_LINKS).filter(Files::isRegularFile).forEach(path -> {
        File file = path.toFile();
        if (file.isDirectory()) {
            return;
        }
        String absolutePath = file.getAbsolutePath();
        String fileExtension = FilenameUtils.getExtension(absolutePath);
        if (!fileExtension.equals("js") && !fileExtension.equals("css")) {
            // We rev only js and css
            return;
        }
        String suffixedName = FilenameUtils.getBaseName(absolutePath) + "_" + suffix + "." + fileExtension;
        File suffixedFile = new File(file.getParentFile(), suffixedName);
        file.renameTo(suffixedFile);
        logger.log("Appended suffix to file: " + absolutePath + ", giving: " + suffixedFile.getAbsolutePath());
    });
}