关闭

batch change file name

363人阅读 评论(0) 收藏 举报
#-------------------------------------------------------------------------------
# Name:        changeDirName
# Purpose:     change directory name
#
# Author:      wind
#
# Created:     29-09-2011
# Copyright:   (c) wind 2011
# Licence:     <your licence>
#-------------------------------------------------------------------------------
#!/usr/bin/env python


import wx
import os


def changeDirName():
    dir = input("please input directory path(example: r'e:\dir'):  ")
    for i in os.listdir(dir):
        newName = oldName = i
        newName = oldName.split('-')[0]
        try:
            os.rename(dir+r'/'+oldName, dir+r'/'+newName)
        except ValueError:
            wx.MessageBox(dir+r'/'+newName, 'Error when rename the file!', wx.OK|wx.ICON_WARNING)
        except NameError:
            wx.MessageBox(dir+r'/'+newName, 'Error when rename the file!', wx.OK|wx.ICON_WARNING)
        except OSError:
            wx.MessageBox(dir+r'/'+newName, 'The file is already exist!', wx.OK|wx.ICON_WARNING)
    wx.MessageBox(dir, 'Change file name success!', wx.OK|wx.ICON_WARNING)


if __name__ == '__main__':
    app = wx.App(False)
    changeDirName()
    app.MainLoop()
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:6211次
    • 积分:167
    • 等级:
    • 排名:千里之外
    • 原创:11篇
    • 转载:0篇
    • 译文:0篇
    • 评论:0条
    文章分类
    文章存档