zoukankan      html  css  js  c++  java
  • 修改某路径下的文件名

    #处理有问题的文件名
    file_name=os.listdir('./2018.5.3')#得到该路径下的所有文件字符串对象
    for temp in file_name:
    try:
    #if '.0_followers' in temp:
    if '.0.xls' in temp:
    new_name=temp.split(".")[0]+'.xls'#将有小数点的文件改为整数名
    # #new_name=re.sub("D", "", temp)+'_followers.xls'
    os.rename('./2018.5.3/'+temp,'./2018.5.3/'+new_name)
    else:
    #os.remove('./test/'+temp)#删掉该文件
    pass
    except Exception as e:
    os.remove('./2018.5.3/' + temp)#若已有重名文件,则删掉
    print(e)
  • 相关阅读:
    每日总结59
    每日总结58
    每日总结57
    每日总结56
    每日总结55
    每日总结54
    每日总结53
    每日总结52
    学习日报
    学习日报
  • 原文地址:https://www.cnblogs.com/kjkj/p/9034675.html
Copyright © 2011-2022 走看看