delwithsuffix.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. # Copyright 2013 The Meson development team
  2. # Licensed under the Apache License, Version 2.0 (the "License");
  3. # you may not use this file except in compliance with the License.
  4. # You may obtain a copy of the License at
  5. # http://www.apache.org/licenses/LICENSE-2.0
  6. # Unless required by applicable law or agreed to in writing, software
  7. # distributed under the License is distributed on an "AS IS" BASIS,
  8. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. # See the License for the specific language governing permissions and
  10. # limitations under the License.
  11. import os, sys
  12. def run(args):
  13. if len(args) != 2:
  14. print('delwithsuffix.py <root of subdir to process> <suffix to delete>')
  15. sys.exit(1)
  16. topdir = args[0]
  17. suffix = args[1]
  18. if suffix[0] != '.':
  19. suffix = '.' + suffix
  20. for (root, _, files) in os.walk(topdir):
  21. for f in files:
  22. if f.endswith(suffix):
  23. fullname = os.path.join(root, f)
  24. os.unlink(fullname)
  25. return 0
  26. if __name__ == '__main__':
  27. run(sys.argv[1:])