1 import os
2>>> base=os.path.basename('/root/dir/sub/file.ext')
3>>> base
4'file.ext'
5>>> os.path.splitext(base)
6('file', '.ext')
7>>> os.path.splitext(base)[0]
8'file'
1import os
2base=os.path.basename('/root/dir/sub/file.ext')
3print(base)
4#'file.ext'
5print(os.path.splitext(base))
6#('file', '.ext')
7print(os.path.splitext(base)[0])
8#'file'
1import os
2
3dir_name = "/Users/ben/downloads/"
4test = os.listdir(dir_name)
5
6for item in test:
7 if item.endswith(".zip"):
8 os.remove(os.path.join(dir_name, item))
9