zoukankan      html  css  js  c++  java
  • 乱七八糟文件夹替换目标文件

    import  os
    import shutil
    os.chdir(r'C:UserslenovoDesktopsjxallsvg')
    goalfile=os.listdir(r'C:UserslenovoDesktopsjxallsvg')
    def replace(path):
    namelist=os.listdir(path)
    for name in namelist:
    absolutepath=os.path.join(path,name)
    if os.path.isfile(absolutepath):
    for i in goalfile:
    if i==os.path.basename(absolutepath):
    print(absolutepath)
    print(i)
    print('*'*20)
    newabsolutepath=absolutepath.rsplit('.')[0]+'_bak'+'.'+absolutepath.rsplit('.')[1]
    shutil.copy2(i,newabsolutepath)
    os.remove(absolutepath)
    os.rename(newabsolutepath,absolutepath)
    elif os.path.isdir(absolutepath):
    replace(absolutepath)
    replace( r'C:UserslenovoDesktopsjxmovetrain')
  • 相关阅读:
    Vue 中常见性能优化
    简单模板引擎实现
    函数柯理化
    url 解析
    快排
    防抖节流实现
    call、apply、bind 实现
    深克隆
    数组去重
    eventEmitter 简单实现
  • 原文地址:https://www.cnblogs.com/diracy/p/13903066.html
Copyright © 2011-2022 走看看