zoukankan      html  css  js  c++  java
  • 读取文件夹中的目录

    import os
    def list_dir(file_dir):
    f=open('C:\Users\10107472\Desktopok.txt','w') #打开文件
    '''
    通过 listdir 得到的是仅当前路径下的文件名,不包括子目录中的文件,如果需要得到所有文件需要递归
    '''
    # print(' <><><><><><> listdir <><><><><><>')
    # print( "current dir : {0}".format(file_dir))
    dir_list = os.listdir(file_dir)
    for cur_file in dir_list:
    # 获取文件的绝对路径
    # path = os.path.join(file_dir, cur_file)
    # print(cur_file)
    # print(type(cur_file))
    a=cur_file
    b=len(a)
    c=b-4
    d=a[c-2:c]
    print(type(b))
    f.write(a[0:3])
    f.write(' ')
    if d=='-X':
    d='擦伤'
    if d=='-崩':
    d='崩边'
    if d=='-划':
    d='划伤'
    f.write(d)
    f.write(' ')
    f.close()
    f=list_dir('C:\Users\10107472\Desktop\POC测试图片NG(已完成坐标)')
  • 相关阅读:
    python3----练习题(斐波那契)
    python3----运算符
    python3----函数、匿名函数
    python3----生成器generator(yield)
    Python捕获异常
    OS模块
    发送邮件
    IO文件读写
    Unittest框架概念
    生成报告
  • 原文地址:https://www.cnblogs.com/tangjunjun/p/11289824.html
Copyright © 2011-2022 走看看