Consider my root dir ls
gives the following output:
1 2 3 4 a b c d
Some files and some dirs. I want to remove all except a few. I can do :
out = subprocess.check_output(['['find', '.', '-maxdepth', '1', '!', '-iname', 'a', '!' '-iname', 'b', '!' '-iname', 'c', '!' , '-iname', 'd', '-exec', 'rm', '-rf', '{}' , '+'])
But I want to specify all not to delete dirs and files in a list instead of making the command so long, and tough to read, ie, something like:
goodfilesList = ['a', 'b','c', 'd']
out = subprocess.check_output(['find', '.', '-maxdepth', '1', '!', '-iname'] + goodfilesList)