Android Folder File List pathContains(String root, String child)

Here you can find the source of pathContains(String root, String child)

Description

Verifies that a path, child, is inside of a parent path root

License

Open Source License

Parameter

Parameter Description
root The root path
child The child path we are checking against

Return

false if the child path exists outside of the root path, true otherwise

Declaration

public static boolean pathContains(String root, String child) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import com.google.common.io.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

public class Main {
    /**//w  ww. j  a va2  s. co  m
     * Verifies that a path, <i>child</i>, is inside of a parent path <i>root</i>
     *
     * @param root  The root path
     * @param child The child path we are checking against
     * @return false if the child path exists outside of the root path, true otherwise
     */
    public static boolean pathContains(String root, String child) {
        Path childPath = Paths.get(Files.simplifyPath(child));
        Path rootPath = Paths.get(root);

        return childPath.startsWith(rootPath);
    }
}

Related

  1. getAllFilesAndFolders(File root, boolean containEmpty)
  2. getFileNames(String dirPath)
  3. getFileNames(String dirPath, FilenameFilter fileNameFilter)
  4. getFiles(File dir, List outList)
  5. listFiles(String fileName)
  6. listFile(File file)
  7. listFiles(File file)
  8. getFileList(File f)
  9. getAllFiles(File root)