import os
def isDirExist(dirPath):
if not os.path.exists(dirPath):
os.makedirs(dirPath)
def isFileExist(filePath):
num = 0
fileType = filePath.split('.')[-1]
fileStr = filePath.split('.' + fileType)[0]
while True:
if os.path.exists(filePath):
filePath = fileStr + '-' + str(num) + '.' + fileType
num += 1
else:
break
return filePath
import os
os.path.isfile(path)
os.path.isdir(path)
improt os
for root, dirs, files in os.walk(path):
for file in files:
fpath = os.path.join(root, file)
print(fpath)
files = os.listdir(path)
for file in files:
fpath = os.path.join(path, file)
print(fpath)
import glob
input_path = r'd:\pic'
img_list=[]
if os.path.isfile(input_path):
img_list = [input_path]
else:
img_list = sorted(glob.glob(os.path.join(input_path, '*')))
print(img_list)