美文网首页
python 监听文件夹

python 监听文件夹

作者: 夜空最亮的9星 | 来源:发表于2021-07-21 22:25 被阅读0次

    文件夹下的文件名是有序生成的。

    下面的函数负责监听文件动态新增

    pip install natsort
    
    import natsort
    
    def read_file_dir():
        current_index = 0
        file_path = '/PycharmProjects/spider/img'
        while True:
            files = os.listdir(file_path)
            file_list = natsort.natsorted(files)
            for _,_ in enumerate(file_list):
                if current_index < len(file_list):
                    img_name = file_path + '/' + file_list[current_index]
                    print(img_name)
                    current_index += 1
    
    read_file_dir()
    

    相关文章

      网友评论

          本文标题:python 监听文件夹

          本文链接:https://www.haomeiwen.com/subject/adysmltx.html