美文网首页
批量重命名_Python

批量重命名_Python

作者: 梓华 | 来源:发表于2018-02-20 20:24 被阅读8次
    # -*- coding: utf-8 -*-
    
    import os
    
    def renameMethod():
        print('rename...')
    
        path = raw_input('请输入文件夹路径:')
        print '目标路径是:',path
    
        fileList = os.listdir(path)
        print '总共',len(fileList),'文件'
    
        i = 0
        for file in fileList:
            oldPath = os.path.join(path, file)
            newName = 'py_auto_rename_%04ld'%i + '.png'
            newPath = os.path.join(path, newName)
    
            os.rename(oldPath, newPath)
    
            i += 1
    
        print('rename end')
    
    def about():
        print('about:luckzihua@126.com')
    
    def main():
        renameMethod()
        
    if __name__ == '__main__':
        print('0:开始\n1:关于\n请输入:')
    
        choose = input()
    
        if choose == 0:
            renameMethod()
        else:
            about()
    else:
        pass
    

    相关文章

      网友评论

          本文标题:批量重命名_Python

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