1.得到文件夹下的所有文件
2.得到路径下的子文件夹
3.创建文件夹
def getFiles(path):
Filelist = []
for home, dirs, files in os.walk(path):
for file in files:
# 文件名列表,包含完整路径
file_path = os.path.join(home, file).replace('\\', '/')
Filelist.append(file_path)
#Filelist.append(file)
return Filelist
def getSubfolder(path):
Filelist = []
for dirpath, dirnames, filenames in os.walk(path):
file_count = 0
for file in filenames:
file_count = file_count + 1
Filelist.append(dirpath)
#print(dirpath,file_count)
return Filelist
def mkdir(path):
folder = os.path.exists(path)
if not folder:
os.makedirs(path)
print(path + "---OK---")
else:
print(path + "---There is this folder!---")