Hello,
I want to remove files from a directory if they are contained also in another one.
For example:
dir1 = {file1, file2}
dir2 = {file2}
I want to remove file2 from dir1.
I’m trying to get the 2 sets of files with fileTree, but I don’t know how to remove a fileTree from the other one.
Could you help me please?
Thanks
Lance_Java
(Lance Java)
2
def fileNames = fileTree(dir1).files.collect {
it.name
} as Set
def deleteTree = fileTree(dir2).matching {
fileNames.each {
include "**/$it.name"
}
}
delete deleteTree
Continuing the discussion from Remove from fileTree:
I did this workaround
def files1 = [] fileTree(dir: path_to_tar + "shared_libs/").visit { FileVisitDetails file -> files1 << file.name } def files2 = [] fileTree(dir: path_to_tar + "libs/").visit { FileVisitDetails file -> if (!files1.contains(file.name)) { files2 << file.name } } delete fileTree(dir: path_to_tar + "libs/", exclude: files2)
amd it works. Later i will try your solution that seems great.
Thanks!