import os
dirct = 'D:/data'
dirList=[]
fileList=[]
files=os.listdir(dirct)  #文件夹下所有目录的列表
print('files:',files)
for f in files:
    if os.path.isdir(dirct + '/'+f):   #这里是绝对路径,该句判断目录是否是文件夹
        dirList.append(f)
    elif os.path.isfile(dirct + '/'+f):#这里是绝对路径,该句判断目录是否是文件
        fileList.append(f)
print("文件夹有:",dirList)
print("文件有:",fileList)

 注:os.path.exists(path):判断路径path是否存在

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-14
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-08
相关资源
相似解决方案