9 except NameError: # Python 3
13 if __name__ == '__main__':
14 parser = argparse.ArgumentParser(description='Remove files/directories')
15 parser.add_argument('-f', '--force', action='store_true',
16 help='force (ignore non-existing files and errors)')
17 parser.add_argument('-r', '--recursive', action='store_true',
18 help='remove directories recursively')
19 parser.add_argument('names', nargs='+',
20 help='files/directories names to remove')
21 args = parser.parse_args()
23 for name in args.names:
24 if args.force and not os.path.exists(name):
26 is_dir = os.path.isdir(name)
27 if not os.access(name, os.W_OK):
35 "rm.py: remove write-protected %s '%s'? [y/n] "
37 answer = rmw[:1].lower()
48 shutil.rmtree(name, args.force)