pdxBlacklist.py 文件源码

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

项目:pdxBlacklist 作者: MaxSalm 项目源码 文件源码
def blankAFile(file_path):
    '''
    truncate a file to zero bytes, and preserve its original modification time
    Adapted from 'Keeping Large intermediate files' (http://www.ruffus.org.uk/faq.html)

    :param file: Input file path
    :return: None
    '''
    if os.path.exists(file_path):
        timeInfo = os.stat(file_path) # retrieve current time stamp of the file
        try:
            f = open(file_path,'w')
        except IOError:
            pass
        else:
            f.truncate(0)
            f.close()
            # change the time of the file back to what it was
            os.utime(file_path,(timeInfo.st_atime, timeInfo.st_mtime))
            print file_path + ' blanked to save disk-space.'
    else:
        print 'blankAFile: ' + file_path + ' not found.'
        sys.exit(1)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号