java - Regex that matches files in passed in folder -
i have list of files
a/b/c a/b/c.data a/b/c/d a/b/c/d.data
when pass in folder path a/b/, want return list of strings of files in folder. in case, a/b/c , a/b/c.data should returned. have tried (a\/b\/).+(?!\/) string.matches(<regex>) returns true them.
ps: file name doesn't end /.
try using files.walk
files .walk(paths.get("your_path")) .foreach(system.out::println); if want files this:
files .walk(paths.get("your_path")) .map(path::tofile) // convert paths files .filter(file::isfile) // filter remove directories .map(file::tostring) // convert files strings .collect(collectors.tolist()); // return list of strings
Comments
Post a Comment