batch change file name

原创 2012年03月27日 14:25:35
#-------------------------------------------------------------------------------
# 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()
版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

file name group

spring batch 任务运行时提示No job configuration with the name解决办法

spring batch 任务运行时提示No job configuration with the name解决办法开发环境 spring boot spring batch idea jdk8 wi...
  • atlim
  • atlim
  • 2017-07-14 16:35
  • 229

Change Log of Joomsport: Add Tournament-Season Name to Group List

Target Add T-S name to group list to make it more readable and user friendly, remove order temp...

Change Oracle Service Name

今天研究了一个小问题,之前成功安装了Oracle, 但是安装的时候没有修改默认的数据库全局名和服务名; 这样的话两个名称就会按照DB_UNIQUE_NAME.DB_DOMAIN 参考:oracle ...

Change Host Name or Port Num in R12 EBS

We ve choices to changing the host name in Oracle application R12.one of the choices is to change th...

start up script batch file

cmd batch file

《Batch File Programming》读书笔记(三)

《Batch File Programming》读书笔记(三)Batch File Programming读书笔记三 条件语句if 目录相关dirmkdirrmdirchdir 文件相关renrepl...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)