web_get_iplayer.py 文件源码

python
阅读 16 收藏 0 点赞 0 评论 0

项目:web_get_iplayer 作者: speculatrix 项目源码 文件源码
def delete_files_by_inode(inode_list, del_img_flag):
    """scan the downloaded list of files and delete any whose inode matches
    one in the list"""

    file_list = os.listdir(my_settings.get(SETTINGS_SECTION, 'iplayer_directory'))

    for file_name in sorted(file_list):
        full_file = os.path.join(my_settings.get(SETTINGS_SECTION, 'iplayer_directory'), file_name)
        if os.path.isfile(full_file):    # need to check file exists in case its a jpg we already deleted
            file_stat = os.stat(full_file)
            #print 'considering file %s which has inode %d\n<br >' % (full_file, file_stat[stat.ST_INO], )

            if str(file_stat[stat.ST_INO]) in inode_list:
                print 'file %s is being deleted \n<br >' % (full_file, )
                try:
                    os.remove(full_file)
                except OSError: # for some reason the above works but throws exception
                    print 'error deleting %s\n<br />' % full_file

                if del_img_flag:
                    file_prefix, _ignore = os.path.splitext(full_file)
                    image_file_name = file_prefix + '.jpg'
                    if os.path.isfile(image_file_name):
                        print 'image %s is being deleted \n<br >' % image_file_name
                        try:
                            os.remove(image_file_name)
                        except OSError: # for some reason the above works but throws exception
                            print 'error deleting %s\n<br />' % (image_file_name, )
                    else:
                        print 'there was no image file %s to be deleted\n<br >' % (image_file_name, )


#####################################################################################################################
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号