p0007 删除文件和文件夹

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import os


def (path):
if os.path.exists(path):
for item in os.listdir(path):
item = os.path.join(path, item)
if os.path.isdir(item):
func(item)
else:
os.remove(item)
os.removedirs(path)
else:
raise TypeError("路径错误!")


# print(help(os.path.exists)/)
path = input("请输入路径:")
func(path)