I am using Files.walk
function to get the files present in a sub directory of a main directory. for example :
/path/to/stuff/foo/bar1/myfile.sql
/path/to/stuff/foo/bar1/myfiles.sql
/path/to/stuff/foo/bar2/myfile.sql
/path/to/stuff/foo/bar3/myfile.sql
/path/to/stuff/foo/bar4/myfile.sql
/path/to/stuff/foo/bar5/
/path/to/stuff/foo/bar6/myfile.sql
/path/to/stuff/foo/bar7/myfile.sql
/path/to/stuff/foo/bar8/myfile.sql
/path/to/stuff/foo/bar9/myfile.sql
this is my code :
Files.walk(Paths.get("/path/to/stuff")).forEach(filePath -> {
if (Files.isRegularFile(filePath)) {
buildFiles();
}
});
in the buildFiles i need to get the filename and the subfoldername and make that as a file name example loop 1 : path=/path/to/stuff/foo/bar1/myfile.sql
and the filename should be foo_bar1.sql
. How would i do that?