Get this path this path, a specific folder and all files names. As shown below:
import os
os.getcwd() #获取当前路径
os.chdir("C:\\Users\\Administrator\\Desktop\\图片") #设置文件夹所在的位置
os.listdir(".")
The results are as follows:
If the file name suffix removed, you can add the following code
os.chdir("C:\\Users\\Administrator\\Desktop\\图片")
filename=os.listdir(".")
name=[]
for i in filename:
portion = os.path.splitext(i) #把文件名拆分为名字和后缀
if portion[1] == ".zip":
name.append(portion[0])
if portion[1] == ".png":
name.append(portion[0])
The results as shown below: